Setting up the ODBC environment (Linux and UNIX)
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
Procedure
For ODBC applications on UNIX that need to access a Db2 database, perform the following steps:
- 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):- in the
[ODBC Data Source]
stanza:
which indicates that there is a data source called SAMPLE that uses the IBM® Db2 ODBC DRIVER;[SAMPLE] DESCRIPTION = Connection to Db2 DRIVER = Db2
- in the
[SAMPLE]
stanza:on AIX®, for example,[SAMPLE] Driver=/u/thisuser/sqllib/lib/libdb2.a Description=Sample Db2 ODBC Database
which indicates that the SAMPLE database is part of the Db2 instance located in the directory /u/thisuser.
With the introduction of the 64-bit development environment, there have been a number of inconsistencies among vendors regarding the interpretation of the sizes of certain parameters. For example, the 64-bit Microsoft ODBC Driver Manager treats SQLHANDLE and SQLLEN as both 64-bits in length, whereas Data Direct Connect and open source ODBC driver managers treat SQLHANDLE as 64-bit, but SQLLEN as 32-bit. The developer must therefore pay careful attention to which version of the Db2 driver is required. Specify the appropriate Db2 driver in the data source stanza, according to the following information:Type of application Db2 driver to specify 32-bit CLI libdb2.* 32-bit ODBC Driver Manager libdb2.* 64-bit CLI libdb2.* 64-bit ODBC Driver Manager libdb2o.* (db2o.o for AIX) Note: The file extension of the Db2 driver to specify depends on the operating system. The extensions are as follows:- .a - AIX
- .so - Linux, HP-IPF
- .sl - HP-PA
- in the
- 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 Linux 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.