Contents | Prev | Next

3.5.1.1 Connecting to ODBC databases

What is ODBC?

The Open Database Connectivity (ODBC) interface is widely used to access Database Management Systems (DBMSs). ODBC was originally created by Microsoft but has now become an industry standard, and is supported by all major DBMSs for Windows.

Connecting to ODBC databases

In order to connect to an ODBC database, you need to:

  1. Declare a variable of the built-in type connection
  2. Use new on the variable to create a connection object
  3. Invoke the open method of the connection object
The open method of the connection object takes one argument, the connection string. ODBC connection strings can take one of two forms:

odbc-connection-string = odbc-connection-string-1 | odbc-connection-string-2

odbc-connection-string-1 = 'ODBC' ';' dsn-parm ';' uid-parm ';' pwd-parm [';' [driver-specific-text]]

odbc-connection-string-2 = 'ODBC' ';' name ';' [uid] ';' [password]

dsn-parm = 'DSN' '=' name

uid-parm = 'UID' '=' uid

pwd-parm = 'PWD' '=' [password]

where [] indicates optional parameters

and name is a valid data source name (DSN)

and uid is an identifier for the user accessing the database

and password is the password of the user accessing the database

For example DSN=test;UID=sa;PWD=

When the connection string is in the first form then it is passed, without further processing, to SQLDriverConnect to open the connection. When the connection string is in the second form then the name, id, and password parameters are extracted from the connection string, if present, and passed to SQLConnect to open the connection. NOTE: The first form of the connection string is the recommended form, support for the second form is provided for completeness only.

See the Irie Pascal Programmer's Reference Manual for more information.

The authoritative source of information about ODBC is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.

Contents | Prev | Next