This topic explains how to set up client access to DB2® databases for ODBC applications in Linux and UNIX operating systems. If your application is a CLI application, you are only required to perform the task in the Before you begin section to set up your environment.
Before you begin
Before setting up the ODBC environment, ensure you have set up the CLI environment.
About this task
For ODBC applications on UNIX that need to access a DB2 database, follow the steps described below.
Procedure
- Ensure that an ODBC driver manager is installed and that each user that will use ODBC has access to it. DB2 does not install an ODBC driver manager, so you must use the ODBC driver manager that was supplied with your ODBC client application or ODBC SDK in order to access DB2 data using that application.
- Set up .odbc.ini, the end-user's data source configuration. Each user ID has a separate copy of this file in their home directory. Note that the file starts with a dot. Although necessary files are usually updated automatically by the tools on most platforms, users of ODBC on UNIX platforms will have to edit them manually.
Using an ASCII editor, update the file to reflect the appropriate data source configuration information. To register a DB2 database as an ODBC data source there must be one stanza (section) for each DB2 database.
The .odbc.ini file must contain the following lines (examples refer to configuration of the SAMPLE database data source):
- Ensure that the application execution environment has reference to the ODBC driver manager by including the corresponding shared library in the environment variable for the library path. The following table indicates the library name by operating system
Operating system | Environment variable | Library name |
---|
AIX | LIBPATH | libodbc.a |
HP-UX, Linux, and Solaris | LD_LIBRARY_PATH | libodbc.so |
- Enable a system-wide .odbc.ini file to be used by setting the ODBCINI environment variable to the fully qualified pathname of the .ini file. Some ODBC driver managers support this feature which allows for centralized control. The following examples show how to set ODBCINI:
in the C shell,
setenv ODBCINI /opt/odbc/system_odbc.ini
in the Bourne or Korn shell,
ODBCINI=/opt/odbc/system_odbc.ini;export ODBCINI
- Once the .odbc.ini file is set up, you can run your ODBC application and access DB2 databases. Refer to the documentation that comes with your ODBC application for additional help and information.
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.apdv.cli.doc/doc/t0006349.html
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.apdv.cli.doc/doc/t0010406.html
http://www.unixodbc.org/doc/db2.html