dbOpenODBC

function

Library: Database access (OMDB legacy)
Include: omdb.xin

Returns: A dbDatabase object for the opened database connection.


Declaration
define external dbDatabase function dbOpenODBC
          value string dsn

or

define external dbDatabase function dbOpenODBC
          value string dsn
    user  value string user-name
 password value string password

Argument definitions

dsn
is the named data source you want to be connected.
user-name
is the user name that will be supplied to the database when the connection is made.
password
is the password that will be supplied to the database when the connection is made.


Purpose

Use dbOpenODBC to create a connection to an ODBC-compliant database. The function returns a dbDatabase OMX component.

Requirements

You must include the following line at the beginning of your OmniMark program:

  include "omdb.xin"

dsn must:

Else external exception OMDB501 is thrown.

User-name and password are optional with default values of an empty string. Check the requirements for access to the specified database.

Usage Notes

You must have declared an OMX dbDatabase variable (either global or local) to reuse a database connection in other omdb functions.

This function will throw external exception OMDB501 if there are any ODBC driver errors. The exception will include any error numbers and descriptive text generated by the ODBC driver. Consult your driver documentation for further details on the error condition.

Example #1:

Create a connection to the ODBC compliant database named DatabaseDemo. No user-name or password is required to access this database. This connection can be reused in other omdb functions.

  include "omdb.xin"
  
  process
    local dbDatabase my-database
    	. . .
    set my-database to dbOpenODBC "DatabaseDemo"

Example #2:

Create a record set from a query to an unopened ODBC compliant database named Collection1. A user-name and password are required to access this database. Note that you will be unable to reuse this connection in other omdb functions as it has not been assigned to a variable. The connection will close automatically when it is out of scope.

  include "omdb.xin"
  global dbField my-query variable initial-size 0
  
  process
     dbQuery dbOpenODBC "Collection1"
    	user "Phred123"
    	password "ecorde143"
       SQL (  'SELECT EmpName, EmpName, {fn ucase(EmpName)}, Salary '
               || 'FROM Employee'  )
     record my-query