Registering ODBC data sources for applications that use the IBM Data Server Driver for ODBC and CLI product

You need to register the IBM Db2® ODBC driver with the ODBC driver manager when you are connecting to multiple databases from different vendors, using different versions of the IBM Db2 ODBC driver, or when your ODBC application is on the Windows operating system. The ODBC driver manager is not part of IBM data server product installation and must be obtained separately from third-party vendors. In the Windows operating system, the ODBC driver manager is part of the operating system.

Before you begin

To register the IBM Db2 ODBC driver and data source with the ODBC driver manager, the following requirement must be met.

About this task

The name of the IBM Db2 ODBC driver library file is db2app.dll on Windows operating systems, and db2app.lib on other platforms. If you installed the IBM Data Server Driver for ODBC and CLI product, the driver library file is located in the lib subdirectory of the directory in which you installed the IBM Data Server Driver for ODBC and CLI product.

Procedure

Steps to register the IBM Db2 ODBC driver depend on the operating system and the ODBC driver manager you installed.

  • For the Windows operating system, you can use the following steps:
    1. Register the IBM Db2 ODBC driver with the Microsoft ODBC Data Source Administrator by using the db2cli install -setup command.
    2. Register the database as an ODBC data source.
  • For operating system other than Windows, you must install third-party ODBC driver manager. You can use the following steps if you installed the open source ODBC driver manager:
    1. Identify the database as an ODBC data source by adding database information to the odbc.ini file.
    2. Associate the IBM Db2 ODBC driver with the data source by adding it in the database section of the odbc.ini file. You must use the fully qualified library file name. If you have multiple copies of the IBM Data Server Driver for ODBC and CLI product installed, you must ensure that the intended copy is identified in the odbc.ini file of the ODBC driver manager. The odbc.ini file is associated with the ODBC driver manager and is not part of the IBM data server product installation.

Results

In Windows operating system, you can use the db2cli registerdsn command to create ODBC data source entries from the following sources2.
  • The db2cli.ini file
  • The IBM data server driver configuration file (db2dsdriver.cfg)
  • Database entries that are specified in the LDAP server3
The db2cli registerdsn command provides the following additional ODBC data source functions.
  • Lists all the Db2 system or user data sources that are already registered in the Microsoft ODBC Data Source Administrator.
  • Removes the system or user data sources that are already registered in the Microsoft ODBC Data Source Administrator.
  • Test database connectivity using the ODBC data source entry.

The db2cli registerdsn command is supported only on the Microsoft Windows operating systems.

Example

You want to register ODBC data sources with an open source driver manager under the listed conditions:
  • The operating system for the target database server is AIX®.
  • There are two copies of the IBM Data Server Driver for ODBC and CLI product installed.
    • $HOME/db2_cli_odbc_driver1 and
    • $HOME/db2_cli_odbc_driver2
  • You have two ODBC database applications:
    • ODBCapp_A
      • ODBCapp_A connects to two data sources, db1 and db2
      • The application can use the copy of the IBM Db2 ODBC driver that is installed at $HOME/db2_cli_odbc_driver1.
    • ODBCapp_B
      • ODBCapp_B connects to the data source db3
      • The application can use the copy of the IBM Db2 ODBC driver that is installed at $HOME/db2_cli_odbc_driver2.

To register ODBC data sources with an open source driver manager, add the example entries in the odbc.ini file:

[db1]
Driver=$HOME/db2_cli_odbc_driver1/lib/libdb2.a
Description=First ODBC data source for ODBCapp1, 
       using the first copy of the IBM Data Server Driver for ODBC and CLI

[db2]
Driver=$HOME/db2_cli_odbc_driver1/lib/libdb.a
Description=Second ODBC data source for ODBCapp1, 
       using the first copy of the IBM Data Server Driver for ODBC and CLI

[db3]
Driver=$HOME/db2_cli_odbc_driver2/lib/libdb2.a
Description=First ODBC data source for ODBCapp2, 
       using the second copy of the IBM Data Server Driver for ODBC and CLI
1 Applicable for operating systems other than the Windows operating system
2 You can also create ODBC data source entries from the cataloged database entry. However, you cannot create cataloged database entry with the IBM Data Server Driver for ODBC and CLI product and the IBM Data Server Driver Package product.
3 You must ensure that you can connect successfully to the LDAP server by configuring the LDAP section in the IBM data server driver configuration file or configuring the LDAP connection in your Windows environment.