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:
- Register the IBM DB2 ODBC
driver with the Microsoft ODBC
Data Source Administrator by using the db2cli install -setup command. See Registering the IBM Data Server Driver for ODBC and CLI with the Microsoft ODBC driver manager.
- Register the database as an ODBC data source. See Setting up the Windows CLI environment.
- 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:
- Identify the database as an ODBC data source by adding
database information to the odbc.ini file. See Setting up the ODBC environment (Linux and UNIX).
- 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 sources
2.
- 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