DB2 Version 9.7 for Linux, UNIX, and Windows

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.

About this task

For ODBC applications on UNIX that need to access a DB2 database, follow the steps described below.

Before you begin

Before setting up the ODBC environment, ensure you have set up the CLI environment.

Procedure

  1. 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.
  2. 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:
         SAMPLE=IBM DB2 ODBC DRIVER
      which indicates that there is a data source called SAMPLE that uses the IBM® DB2 ODBC DRIVER;
    • in the [SAMPLE] stanza:
      on AIX®, for example,
         [SAMPLE]
         Driver=/u/thisuser/sqllib/lib/libdb2.a
         Description=Sample DB2 ODBC Database
      on the Solaris operating system, for example,
         [SAMPLE]
         Driver=/u/thisuser/sqllib/lib/libdb2.so
         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, Solaris, HP-IPF
      • .sl - HP-PA
  3. 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
  4. 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
  5. 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.