skip to main content
Using the ODBC Client : Connecting Using a Connection String
 

Connecting Using a Connection String

If you want to use a connection string for connecting to a database, or if your application requires it, you must specify either a DSN (data source name) or a DSN-less connection in the string. The difference is whether you use the DSN= or the DRIVER= keyword in the connection string, as described in the ODBC specification. A DSN connection string tells the driver where to find the default connection information. Optionally, you may specify attribute=value pairs in the connection string to override the default values stored in the data source.
If your application requires a connection string to connect to a data source, you must specify the data source name that tells the driver which data source to use for the default connection information. Optionally, you may specify attribute=value pairs in the connection string to override the default values stored in the data source.
The DSN connection string has the form:
DSN=data_source_name[;attribute=value[;attribute=value]...]
For example, a connection string may look like this:
DSN=Accounting;DB=EMP;UID=JOHN;PWD=XYZZY
or
DSN=Accounting;DB="X:IV;EMP";UID=JOHN;PWD=XYZZY
Note: If the database name (DB) contains a semicolon (;), you must place the name in quotes, as shown in the preceding example.
The DSN-less connection string specifies a driver instead of a data source. All connection information must be entered in the connection string because there is no data source storing the information.
The DSN-less connection string has the form:
DRIVER=[{]driver_name[}][;attribute=value[;attribute=value]
...]
Note: Empty string is the default value for attributes that use a string value unless otherwise noted.
A DSN-less connection string must provide all necessary connection information:
DRIVER=DataDirect OpenAccess SDK 8.1;DB=Emp;UID=JOHN;PWD=XYZZY
See Specifying ODBC Connection Attributes for a list of ODBC connection attributes and their valid values.
See DSN-less Connections in Linux and UNIX for more information about using DSN-less connections.