DB2 Connect Quick Beginnings for Linux**

Running CLI/ODBC Programs

The DB2 Call Level Interface/ODBC driver (which consists of the DB2 Call Level Interface run-time environment and the DB2 ODBC driver) is included with the DB2 Connect Personal Edition.

This support enables applications developed using ODBC and DB2 CLI APIs to work with any DB2 server or DB2 Connect Personal Edition workstation. DB2 CLI application development support is provided by the DB2 Application Development Client which is packaged with a DB2 Connect server.

Before DB2 CLI or ODBC applications can access DB2, the DB2 CLI packages must be bound on any remote server to be accessed by this application. See Binding Database Utilities for specific details.

The following general steps are required on DB2 Connect Personal Edition to give DB2 CLI and ODBC applications access to remote DB2 databases. These instructions assume that you have successfully connected to DB2 using a valid user ID and password. Depending on the platform many of these steps are automatic.

Step  1.

Use the Control Center to add the database so that its instances and databases can be made known to the Control Center, then add the instances and databases for that system. (Your local system is represented by Local icon.) If you do not have access to this program you can use the catalog command in the command line processor.

Step  2.

The DB2 CLI/ODBC driver is an optional component that you can install. Be sure it is was installed at that point.

Step  3.

To access the DB2 database from ODBC/CLI:

  1. The ODBC Driver Manager (From Microsoft or other vendor) must already be installed.
  2. The DB2 databases must be registered as ODBC data sources. The ODBC driver manager does not read the DB2 catalog information; instead it references its own list of data sources.
  3. If a DB2 table does not have a unique index then many ODBC applications will open it as read-only. A unique index should be created for each DB2 table that is to be updated by an ODBC application. Refer to the CREATE INDEX statement in the SQL Reference. Using the Control Center you would alter the settings of the table, then select the Primary Key tab and move one or more columns from the available columns list over to the primary key columns list. Any column you select as part of the primary key must be defined as NOT NULL.

Step  4.

If necessary, you can set various CLI/ODBC Configuration Keywords to modify the behavior of DB2 CLI/ODBC and the applications using it.

If you followed the above steps to install ODBC support, and added DB2 databases as ODBC data sources, your ODBC applications will now be able to access them.

Platform Specific Details for CLI/ODBC Access

Before DB2 CLI and ODBC applications can successfully access a DB2 database from a UNIX client, perform the following steps on the client system:

  1. The DB2 database (and node if the database is remote) must be cataloged. To do so, use the command line processor.

    For more information see the CATALOG DATABASE and CATALOG NODE commands in the Command Reference.

  2. The DB2 CLI/ODBC driver is an optional component during the DB2 client install. Be sure it is selected at that point.
  3. If you are using ODBC applications to access DB2 data, perform the following steps. (If you are using only CLI applications, skip this step and go to the next step.)
    1. When using an ODBC application you must 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, 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. The Driver Manager uses two initialization files.

      odbcinst.ini
      ODBC Driver Manager's configuration file indicating which database drivers are installed. Each user that will use ODBC must have access to this file.

      .odbc.ini
      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.

      Setting up odbcinst.ini

      The settings in this file impact all of the ODBC drivers on the machine.

      Use an ASCII editor to update this file. It must have a stanza (section) called [IBM DB2 ODBC DRIVER], with a line starting with "Driver" indicating the full path to the DB2 ODBC driver (db2.o). For example, if the home directory of your end user is /home/thisuser/ and the sqllib directory is installed there, then the correct entry would be:

         [IBM DB2 ODBC DRIVER]
         Driver=/home/thisuser/sqllib/lib/db2.o
      

      Setting up .odbc.ini

      The settings in this file are associated with a particular user on the machine; different users can have different odbc.ini files.

      The .odbc.ini file must exist in the end user's home directory (note the dot at the start of the file name). Update this file, using an ASCII editor, 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:

      • in the [ODBC Data Source] stanza:
           SAMPLE=IBM DB2 ODBC DRIVER
        

        Indicates that there is a data source called SAMPLE that used the IBM DB2 ODBC DRIVER.

      • in the [SAMPLE] stanza:
           [SAMPLE]
           Driver=/home/thisuser/sqllib/lib/db2.o
           Description=Sample DB2 ODBC Database
        

        Indicates that the SAMPLE database is part of the DB2 instance located in the directory /home/thisuser.

      • in the [ODBC] stanza:
           InstallDir=/home/thisuser/sqllib/odbclib
        

        Indicates that /home/thisuser/sqllib/odbclib should be treated as the location where ODBC is installed.

      • Ensure that the InstallDir correctly points to the ODBC Driver Manager location.

        For example, if the ODBC Driver Manager has been installed in /opt/odbc, the [ODBC] stanza would look like:

           [ODBC]
           Trace=0
           TraceFile=odbctrace.out
           InstallDir=/opt/odbc
        

      See the sample file in the sqllib/odbclib subdirectory for an example.

      Once the .ini files are 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.

  4. Configure the DB2 CLI/ODBC driver (Optional).

    There are various keywords and values that can be used to modify the behavior of DB2 CLI/ODBC and the applications using it. The keywords are associated with the database alias name, and affect all DB2 CLI/ODBC applications that access the database.

    For information on manually editing this file (db2cli.ini), see Configuring db2cli.ini. For information about the specific keywords refer to the CLI Guide and Reference.



note

If you require additional information at this point you can refer to the following topics in Detailed Configuration Information:

Detailed Configuration Information

The section Platform Specific Details for CLI/ODBC Access should provide you with all of the information you require. The following additional information is useful where DB2 tool support is not available, and for administrators who require more detailed information.

The following topics are covered in this section:

How to Bind the DB2 CLI/ODBC Driver to the Database

The CLI/ODBC driver will autobind on the first connection to the database, provided the user has the appropriate privilege or authorization. The administrator may want to perform the first connect or explicitly bind the required files. For more information, see Binding Database Utilities.

How to Set CLI/ODBC Configuration Keywords

DB2 CLI can be configured further by manually editing the db2cli.ini file.

This file contains various keywords and values that can be used to modify the behavior of DB2 CLI and the applications using it. The keywords are associated with the database alias name, and affect all DB2 CLI and ODBC applications that access the database.

By default, the location of the CLI/ODBC configuration keyword file is located in the in the INSTHOME/sqllib/cfg directory (where INSTHOME is the home directory of the instance owner) that is running the CLI/ODBC applications on Linux platforms.

The environment variable DB2CLIINIPATH can also be used to override the default and specify a different location for the file.

The configuration keywords enable you to:

For a complete description of keywords and their usage, refer to the Installation and Configuration Supplement online document.

Configuring db2cli.ini

The db2cli.ini initialization file is an ASCII file which stores values for the DB2 CLI configuration options. A sample file is shipped to help you get started. Refer to the CLI Guide and Reference for information on each keyword.

See Platform Specific Details for CLI/ODBC Access for more information on how to modify this file on your platform.


[ Top of Page | Previous Page | Next Page ]