Connecting to a Data Source 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), a File DSN, or a DSN-less connection in the string. The difference is whether you use the DSN=, FILEDSN=, or the DRIVER= keyword in the connection string, as described in the ODBC specification. A DSN or FILEDSN 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.

The DSN connection string has the form:

DSN=data_source_name[;attribute=value[;attribute=value]...] 

The FILEDSN connection string has the form:

FILEDSN=filename.dsn[;attribute=value[;attribute=value]...] 

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]
...] 

Table 4-1 gives the long and short names for each attribute, as well as a description. You can specify either long or short names in the connection string. Connection string attribute names are the same as the option names on the driver Setup dialog box tabs unless otherwise noted. The connection string attribute name does not have spaces between the words. For example, the connection string attribute name ApplicationUsingThreads is equivalent to the option name Application Using Threads.

The defaults listed in the table are initial defaults that apply when no value is specified in either the data source definition or in the connection string. If you specified a value for the attribute when configuring the data source, that value is the default. Note that if no default value is listed in the table for attributes that use a string value, an empty string is the default value.

An example of a DSN connection string with overriding attribute values for DB2 for Linux/UNIX/Windows is:

DSN=DB2ACCOUNT;DB=DB2DATA;UID=JOHN;PWD=XYZZY 

A FILEDSN connection string is similar except for the initial keyword:

FILEDSN=DB2.dsn;DB=DB2DATA;UID=JOHN;PWD=XYZZY 

A DSN-less connection string must provide all necessary connection information:

DRIVER=DataDirect DB2 Wire Protocol; 
IpAddress=123.456.78.90;PORT=5179;DB=DB2ACCT;UID=JOHN; 
PWD=XYZZY 
 

Table 4-1. DB2 Wire Protocol Connection String Attributes 
Attribute
Description
AddStringTo
CreateTable (ASCT)
A string that is automatically added to all Create Table statements. This attribute is primarily for users who need to add an "in database" clause.
The equivalent Setup dialog box option is Add to Create Table.
AlternateID (AID)
Changes the current schema to a user-specified value at connect time. It sets the default qualifier for unqualified object names in SQL statements. If the attempt to change the current schema fails, the connection fails and you receive the message, Invalid value for Alternate ID. DB2 permissions must be set to SYSADM. (This is not valid for DB2 UDB V5R1 for iSeries.)
AlternateServers (ASRV)
A list of alternate database servers to which the driver will try to connect if the primary database server is unavailable. Specifying a value for this connection string attribute enables connection failover for the driver. See "Using Connection Failover" for a discussion of connection failover.
The value you specify must be in the form of a string that defines connection information for each alternate server. For the DB2 Wire Protocol driver, you must specify the IP address, port number, and database name (Linux/UNIX/Windows) or location (z/OS and iSeries) of each alternate server. The string has the format:
(IPAddress=ipvalue:TcpPort=portvalue:{Database | 
Location}=databasevalue[, . . .]) 
For example, the following AlternateServers values define two alternate database servers for connection failover:
AlternateServers=(IpAddress=123.456.78.90:TcpPort=5177:
Database=DB2DAT, IpAddress=223.456.78.90:TcpPort=5178:
Database=DB2DAT3) 
or
AlternateServers=(IpAddress=123.456.78.90:TcpPort=5177:Location=DB2DAT, IpAddress=223.456.78.90:TcpPort=5178:
Location=DB2DAT3)
See "Configuring Connection Failover" for information about other connection options that you can set for this feature.
ApplicationUsing
Threads (AUT)
ApplicationUsingThreads={0 | 1}. Determines whether the driver works with multi-threaded applications.
When set to 1 (the initial default), the driver is thread-safe and is ensured to work with multi-threaded applications.
When using the driver with single-threaded applications, you can set this option to 0 to avoid additional processing required for ODBC thread-safety standards.   
This attribute can affect performance. See "Performance Considerations" for details.
Authentication
Method (AM)
AuthenticationMethod={0 | 1 | 2 | 3 | 4}. Determines the security method the driver uses to authenticate the user to the server when a connection is established.
When set to 0 (the initial default), the driver sends the user ID and password in clear text to the server for authentication.
When set to 1, the driver sends the user ID in clear text and an encrypted password to the server for authentication.
When set to 2, the driver sends an encrypted user ID and password to the server for authentication.
When set to 3, the driver uses client authentication when establishing a connection. The database server relies on the client to authenticate the user and does not provide additional authentication.
When set to 4, the driver uses Kerberos authentication. This method supports both Windows Active Directory Kerberos and MIT Kerberos environments.
If the specified authentication method is not supported by the database server, the connection fails and the driver generates an error.
See "Using Security" for a general description of authentication and its configuration requirements.
CatalogSchema (CS)
Specifies the DB2 schema to use for Catalog functions. The value must be the name of a valid DB2 schema. If you do not specify a value for this attribute, the driver uses SYSIBM when connected to z/OS, QSYS2 when connected to iSeries, and SYSCAT when connected to Linux/UNIX/Windows.
The initial default is an empty string.
CharsetFor65535 (CF6)
CharsetFor65535 ={ 0 | IANA code page value}. Specifies a character set from which to convert when fetching character columns (char, varchar, longvarchar, clob, char for bit data, varchar for bit data, longvarchar for bit data) defined with Coded Character Set Identifier (CCSID) 65535.
When set to 0 (the initial default), the driver returns these columns as binary columns (SQL_BINARY, SQL_VARBINARY, SQL_LONGVARBINARY) and does no conversion of the data.
When set to any valid IANA code page value, the driver returns these columns as character columns and assumes they are being returned in the character set specified. The driver does no conversion of data supplied in bound parameters. See "IBM to IANA Code Page Values" for a table of IANA and IBM code page equivalents.
NOTE: All columns defined as Char for Bit Data, Varchar for Bit Data, and Longvarchar for Bit Data will be affected by this option. By definition, columns created with these types have a CCSID of 65535.
The equivalent Setup dialog box option is Character Set for CCSID 65535.
Collection (COL)
By default, the User ID is used for the value of Collection. The User ID must always be used on DB2 for z/OS. This attribute is valid only if you are connecting to a DB2 database for z/OS or iSeries.
On DB2 for iSeries, you can use the name of the schema that is to be the default qualifier for unqualified object names. If you want to access a table outside of this schema, you need to specify the appropriate two-part name, for example:
SELECT * FROM Schema.Tablename
Collection is also the current library. If the attempt to change the current schema fails, the connection fails and you receive the message, Invalid value for Alternate ID. DB2 permissions must be set to SYSADM. (This is not valid for DB2 V5R1 for iSeries.) Collection is overridden by Alternate ID on iSeries if a value is set for Alternate ID.
ConnectionRetryCount (CRC)
Specifies the number of times the driver tries to connect to the primary server, and if configured, to the alternate servers after the initial unsuccessful attempt. See "Using Connection Retry" for more information about this feature.
Valid values are integers from 0 to 65535. When set to 0 (the initial default), the driver does not try to connect after the initial unsuccessful attempt.
If a connection is not established during the retry attempts, the driver returns an error that is generated by the last server to which it tried to connect.
This attribute and the ConnectionRetryDelay connection string attribute, which specifies the wait interval between attempts, can be used in conjunction with connection failover.
See "Configuring Connection Failover" for a discussion of connection failover and for information about other connection string attributes that you can set for this feature.
ConnectionRetryDelay (CRD)
Specifies the number of seconds that the driver waits after the initial unsuccessful connection attempt before retrying a connection to the primary server and, if specified, to the alternate servers.
Valid values are integers from 0 to 65535. The initial default is 3 (seconds). When set to 0, there is no delay between retries.
NOTE: This attribute has no effect unless the ConnectionRetryCount connection string attribute is set to an integer value greater than 0.
This attribute and the ConnectionRetryCount connection string attribute, which specifies the number of times the driver tries to connect after the initial unsuccessful attempt, can be used in conjunction with connection failover.    
See "Configuring Connection Failover" for a discussion of connection failover and for information about other connection string attributes that you can set for this feature.
Database (DB)
Specifies the name of the database to which you want to connect. This attribute is valid and required only if you are connecting to DB2 for Linux/UNIX/Windows.
The equivalent Setup dialog box option is Database Name.
DataSourceName (DSN)
Specifies a string that identifies a DB2 data source configuration. Examples include Accounting or DB2-Serv1.
DefaultIsolationLevel (DIL)
DefaultIsolationLevel={0 | 1 | 2 | 3 | 4}. Specifies the method by which locks are acquired and released by the system (refer to "Locking and Isolation Levels" in the DataDirect Connect for ODBC and Connect XE for ODBC Reference for details). Valid values are:
0-READ_UNCOMMITTED-Allows other processes to read from the database. Only modified data is locked until the end of the transaction.
1-READ_COMMITTED (the initial default)-Allows other processes to change a row that your application read if the cursor is not on the row that you want to change. It prevents other processes from changing records that your application has changed until your program commits them or terminates. It prevents your program from reading a modified record that has not been committed by another process.
2-REPEATABLE_READ-Prevents any other process from accessing data that your application has read or modified. All read or modified data is locked until the end of the transaction.
3-SERIALIZABLE-Prevents other processes from changing records that are read or changed by your application (including phantom records) until your program commits them or terminates. It prevents the application from reading modified records that have not been committed by another process. If your program opens the same query during a single unit of work under this isolation level, the results table will be identical to the previous table; however, it can contain updates made by your program.
4-NONE-Allows your program to read modified records even if they have not been committed by another user. This level can only be set in the data source, not from the application. (This level is valid only on iSeries, and is the only isolation level that works for collections that have journaling enabled.)
DynamicSections (DS)
Specifies the number of statements that the DB2 Wire Protocol driver package can prepare for a single user. The initial default is 200.
Encryption
Method (EM)
EncryptionMethod={0 | 1 | 2}. Specifies the method the driver uses to encrypt data sent between the driver and the database server.
When set to 0 (the initial default), data is not encrypted.
When set to 1, data is encrypted using SSL (supported only on DB2 for iSeries).
When set to 2, data is encrypted using the DB2 encryption protocol (supported only on DB2 for Linux/UNIX/Windows and DB2 for z/OS).
NOTE: DB2 encryption protocol can only be specified when Authentication Method is set to 0, 1, or 2.
If the specified encryption method is not supported by the database server, the connection fails and the driver returns an error.
See "Using Security" for a general description of encryption and its configuration requirements.
This attribute can affect performance. See "Performance Considerations" for details.
GrantAuthid (GA)
Specifies the name of the schema to which you want to grant EXECUTE privileges for DB2 packages. The value must be a valid DB2 schema. This attribute is ignored if the GrantExecute (GE) connection string attribute is set to 0.
The initial default is PUBLIC.
The equivalent Setup dialog box option is the field that is part of Grant Execute to.
GrantExecute (GE)
GrantExecute ={ 0 | 1}. Determines which DB2 schema is granted EXECUTE privileges for DB2 packages.
When set to 0, EXECUTE privileges are granted to the schema that created the DB2 packages.
When set to 1 (the initial default), EXECUTE privileges are granted to the schema specified by the GrantAuthid (GA) connection string attribute.
GSSClient (GS)
Specifies the GSS client library that the driver uses to communicate with the Key Distribution Center (KDC). The initial default is native, indicating that the driver uses the GSS client that ships with the operating system. The driver uses the standard path for loading the specified client library.
See "Using Security" for a general description of authentication and its configuration requirements.
HostNameInCertificate (HNIC)
Specifies whether the driver validates the host name contained in the certificate returned by the database server on systems using SSL. The host name is established by the SSL administrator. If no value is specified for HostNameInCertificate, the driver does not check the host name in the server certificate. The value of HostNameInCertificate is ignored if ValidateServerCertificate is set to 0 or if EncryptionMethod does not specify SSL.
If a value is specified for HostNameInCertificate, the driver examines the subjectAltName values included in the certificate. If a dnsName value is present in the subjectAltName values, then the driver compares the value specified for HostNameInCertificate with the dnsName value. The connection succeeds if the values match. The connection fails if the HostNameInCertificate value does not match the dnsName value.
If no subjectAltName values exist or a dnsName value is not in the list of subjectAltName values, then the driver compares the value specified for HostNameInCertificate with the commonName part of the Subject name in the certificate. The commonName typically contains the host name of the machine for which the certificate was created. The connection succeeds if the values match. The connection fails if the HostNameInCertificate value does not match the commonName. If multiple commonName parts exist in the Subject name of the certificate, the connection succeeds if the HostNameInCertificate value matches any of the Common Name parts.
See "Using Security" for a general description of encryption and its configuration requirements.
If the value specified for HostNameInCertificate is the special value #SERVERNAME#, then the driver compares the IpAddress (IP) attribute value specified as part of a data source or connection string to the dnsName value or the commonName.
IANAAppCodePage (IACP)

For a list of valid values for this attribute, refer to "Values for the Attribute IANAAppCodePage" in the DataDirect Connect for ODBC and Connect XE for ODBC Reference. You need to specify a value for this attribute if your application is not Unicode-enabled and/or if your database character set is not Unicode (refer to "Internationalization, Localization, and Unicode" in the DataDirect Connect for ODBC and Connect XE for ODBC Reference for details). The value you specify must match the database character encoding and the system locale.
Both this driver and the Driver Manager check for the value of IANAAppCodePage in the following order:
  • In the connection string
  • In the Data Source section of the system information file (odbc.ini)
  • In the ODBC section of the system information file (odbc.ini)
If no IANAAppCodePage value is found, the driver uses the default value of 4 (ISO 8859-1 Latin-1).
IpAddress (IP)
Specifies the IP (Internet Protocol) address of the machine where the catalog tables are stored. Specify the address using the machine's numeric address or specify its address name. If you specify an address name, the driver must find this name (with the correct address assignment) in the HOSTS file on the workstation or in a DNS server. The default is localhost.
The numeric IP address can be specified in either IPv4 or IPv6 format, or a combination of the two. See "Using IP Addresses" for details concerning these formats.
LoadBalancing (LB)
LoadBalancing={0 | 1}. Determines whether the driver uses client load balancing in its attempts to connect to primary and alternate database servers. See "Using Client Load Balancing" for more information.
When set to 1, the driver attempts to connect to the database servers in random order.
When set to 0 (the initial default), client load balancing is not used and the driver connects to each database server based on its sequential order (primary server first, then, alternate servers in the order they are specified).
NOTE: This attribute has no effect unless alternate servers are defined for the AlternateServers connection string attribute.
The LoadBalancing connection string attribute is an optional setting that you can use in conjunction with connection failover. See "Configuring Connection Failover" for a discussion of connection failover and for information about other connection string attributes that you can set for this feature.
Location (LOC)
Specifies the DB2 location name. Use the name defined during the local DB2 installation. This attribute is valid and required only if you are connecting to DB2 for z/OS or iSeries.
On DB2 for z/OS only, your system administrator can determine the name of your DB2 location using the DISPLAY DDF command.
On DB2 for iSeries only, your system administrator can determine the name of your DB2 location using the WRKRDBDIRE command. The name of the database that is listed as *LOCAL is the value you should use.
The equivalent Setup dialog box option is Location Name.
LogonID (UID)
The default user ID used to connect to your database. Your ODBC application may override this value or you may override it in the logon dialog box or connection string.
The equivalent Setup dialog box option is User Name.
PackageCollection (PC)
The collection or location name where the driver creates the bind packages and searches for them when required.
The initial default is NULLID.
PackageOwner (PO)
The AuthID assigned to the bind package. This DB2 AuthID must have authority to execute all the SQL in the package (optional).
Password (PWD)
A password used to connect to your DB2 database.
ReportCodePage
ConversionErrors (RCCE)
ReportCodePageConversionErrors={0 | 1 | 2}. Provides flexibility for the way in which the driver returns error or warning messages associated with code page conversion.
When set to 0 (the initial default), if the driver encounters code page conversion errors (a character cannot be converted from one character set to another), it makes a substitution for each character that cannot be converted and does not return a warning or error.
Settings 1 and 2 apply both to all ODBC API calls that could cause a conversion error and to all code page conversions to and from the database and to and from the application. The error or warning returned is Code page conversion error encountered. In the case of parameter data conversion errors, the driver adds the following sentence: Error in parameter x, where x is the parameter number. The standard rules for returning specific row and column errors for bulk operations still apply.
When set to 1, if the driver encounters code page conversion errors, it returns an error instead of substituting 0x1A for unconverted characters.
When set to 2, if the driver encounters code page conversion errors, it substitutes 0x1A for each character that cannot be converted and returns a warning.
TcpPort (PORT)
The port number that is assigned to the DB2 DRDA listener process on the server host machine. Specify this port's numeric address or its name (50000 is the initial default port address). If you specify a port name, the driver must find this name (with the correct port assignment) in the SERVICES file on the workstation.
On DB2 for iSeries only, execute NETSTAT from an iSeries command line to determine the correct port number. Select option 3 to display a list of active ports on the iSeries machine. Find the entry for DRDA and press F14 to toggle and display the port number. If DRDA is not currently listening, the iSeries command CHGDDMTCPA AUTOSTART(*YES) PWDRQD(*YES) starts the listener and ensures that it is active at IPL.
TrustStore (TS)
The path that specifies the location of the truststore file. The truststore file contains a list of the valid Certificate Authorities (CAs) that are trusted by the client machine for SSL server authentication.
See "Using Security" for a general description of encryption and its configuration requirements.

TrustStorePassword (TSP)
The password required to access the truststore.
See "Using Security" for a general description of encryption and its configuration requirements.

UseCurrentSchema (UCS)
UseCurrentSchema={ 0 | 1}. Specifies whether results are restricted to the tables in the current schema if a catalog function call is made either without specifying a schema or specifying the schema as the wildcard character %. Restricting results to tables in the current schema improves the performance of calls that do not specify a schema.
When set to 1, results returned from catalog function calls are restricted to the tables in the current schema.
When set to 0 (the initial default), results returned from catalog function calls are not restricted.
The equivalent Setup dialog box option is Use Current Schema for Catalog Functions.
This attribute can affect performance. See "Performance Considerations" for details.
ValidateServerCertificate (VSC)
ValidateServerCertificate={0 | 1}. Determines whether the driver validates the security certificate of the server as part of the SSL authentication handshake.
When set to 0, the driver does not validate the certificate.
When set to 1 (the initial default), the driver validates the certificate.
See "Using Security" for a general description of encryption and its configuration requirements.

XMLDescribeType (XDT)
XMLDescribeType ={ -4 | -10}. Specifies the SQL data type returned by SQLGetTypeInfo() for the XML data type.
When set to -4, the driver uses the description SQL_LONGVARBINARY for columns defined as the DB2 XML data type.
When set to -10 (the default), the driver uses the description SQL_WLONGVARCHAR for columns defined as the DB2 XML data type.
See the "Using the XML Data Type" for further information about the XML data type.
WithHold (WH)
WithHold ={ 0 | 1}. Specifies the cursor behavior for the application used with this data source-either DB2 closes all open cursors after a commit or rollback (Delete cursors), or leaves them open (Preserve cursors).
When set to 1 (the initial default), the cursor behavior is Preserve (SQLGetInfo( ) returns SQL_CB_PRESERVE for SQL_COMMIT_CURSOR_BEHAVIOR).
When set to 0, the cursor behavior is Delete (SQLGetInfo( ) returns SQL_CB_DELETE). For information about this function, refer to the Microsoft ODBC API.
The equivalent Setup dialog box option is With Hold Cursors.