You are on page 1of 4

2009 IBM Corporation

How to Configure DB2 Connect using ODBC on Unix to IBM i:


A quick primer

8/13/09
Cindy Munns
Kent Milligan

Using DB2 Connect Version 9.7 for System i from Unix to access data stored in DB2 for i is
straightforward if you follow these steps.

This document summarizes what is needed to:
1. Make a successful command line connection and
2. Configure and connect via ODBC using the UnixODBC Open Source driver manager.

These configuration steps apply to when connecting from both an AIX partition on a Power
Systems server or a standalone Unix server.

Steps to Prepare and Configure your Power Systems server running IBM i:

The following process lists the necessary steps to be performed on the IBM i server (Past
generations of the IBM i server were named AS/400, iSeries, and System i. The associated
operating system for these servers were named OS/400 and i5/OS):

1) Verify that the TCP/IP stack is working correctly. It is assumed that the Virtual LAN is used to
communicate with the IBM i partition. First, obtain the IP address of the IBM i server or its
hostname, and ping the IBM i server from the AIX partition.

2) Find the name of the local relational database directory entry on the IBM i server. The database
directory can be displayed by using the DSPRDBDIRE system command. Make sure you obtain
the name of directory entryy with a location of *LOCAL. Usually this value is the same as the the
TCP/IP host name.

3) Create a library called NULLID using the CRTLIB system command. This is necessary because
the utilities shipped with DB2 Connect and DB2 for AIX store their packages in the NULLID library.
Since it does not exist, by default, on the IBM i server, you must create it using the following
command:
CRTLIB LIB(NULLID)

4) Products that support DRDA automatically perform any necessary code page conversions at
the receiving system. For this to happen, both systems need a translation table from their code
page to the partner code page. If character data is not being correctly translated, then you may
need to alter the Coded Character Set Identifier (CCSID) settings on the IBM i server. Some
systems use the default CCSID on the IBM i server is 65535. Since DB2 Connect does not have a
translation table for this code page, the developer needs to change the individual user profiles to
contain a CCSID that can be converted properly by DB2 Connect. For US English, this is 37. For
other languages, see DB2 Connect Personal Edition Quick Beginning, GC09-2967. The following
IBM i command changes the CCSID for an individual user profile to 37:
CHGUSRPRF userid CCSID(37)

2009 IBM Corporation

5) Verify that the default port 446 for DRDA service is being used. To do this, go to the Configure
TCP/IP menu (CFGTCP), select Configure Related Tables, and then select Work with service
table entries. Verify that the DRDA service is set for port 446.

6) The Distributed Data Management (DDM) job must be started for DRDA to work. If you want the
DDM job to be automatically started whenever TCP/IP is started, change the attributes of the DDM
job using the CHGDDMTCPA command and set the Autostart server parameter to *YES.

7) If the system administrator chooses not to autostart the server, issue the following command to
start the DDM server job:
STRTCPSVR SERVER(*DDM)

8) Make sure that the user profiles that will be used to connect to the IBM i server exist on the
server.


Steps on Unix:

1) Login as root and install DB2 Connect Enterprise Edition.

2) Set up Xwindows for the GUI: Ensure that you have properly exported your display. For
example, export DISPLAY=9.22.234.999:0.

3) Install DB2 Connect using the ./db2setup script. It installs everything including creating users,
instances, etc. etc. You can change install path, include TSA, etc. etc.

4) Turn on Federation dbm cfg parameter: Update dbm cfg federation yes (default is NO).

5) Issue a db2set, confirm you have DB2COMM set to TCPIP: db2set all

6) Ping your remote IBM i host, ensure you get a response. Example: ping 123.45.678.3

7) For Solaris, change kernel parms- run db2osconf from $DB2DIR/bin and compare values to
your own kernel parameters. Update /etc/system file if needed, reboot system.

8) Apply DB2 Connect Activation key using db2licm -a command. Refer to documentation for
instructions. For a trial, you dont need to do this.

9) Connect to a local database to confirm client connectivity. If you created the toolsdb database,
you can connect to that as db2 instance owner (default db2inst1). Otherwise, you can create db2
sample, if desired, using db2sampl script.
db2 connect to toolsdb user myuser using mypassword
You should receive a return prompt with the database name and DB2 release number.

10) Catalog the IBM i node, dcs database, and database:
A) Catalog the node: db2 catalog tcpip node MYINODE remote <ipaddress> server 446
myinode is a logical name arbitrarily assigned to the IBM i server
<ipaddress> is the IBM i server TCP address (Step 1 in first section)
446 is the standard port for DRDA communications which is the method of
communications we use to connect to DB2 for i databases.
2009 IBM Corporation

B) Catalog the DCS database:
db2 catalog dcs database MYIDB2 as <database name>
MYIDB2 is an arbitrary logical name assigned to the IBM i database that's being accessed
<database name> is the name of *LOCAL database directory entry (Step 2 in first section)

C) Catalog the DB2 for i database: db2 catalog db MYIDB2 at node MYINODE
The database and node values (MYIDB2 and MYINODE respectively) are used from steps A and
C.

11) Connect to the DB2 for i database server:
db2 connect to MYIDB2 user myuser using mypassword

You should get a connect prompt showing the connected IBM i system and the release number,
e.g. 5.4. If you get this far, you're halfway there!

12) If you plan to use embedded SQL or use certain utilities, you will need to bind packages on the
IBM i server. While connected, bind the packages on the server with the following db2 command:
db2 bind path@ddcs400.lst blocking all sqlerror continue messages ddcs400.msg
grant public

13) Install and configure an ODBC Driver Manager. This is not included with Connect. UnixODBC
has an Open Source version, which is a package install on Solaris. Instructions are here:
http://www.unixodbc.org.
A. Create the odbc driver file, odbcinst.ini to point at the DB2 ODBC driver:
We used the global odbcinst.ini file, it should look like this. Note that the driver name will depend
on your OS and whether you are using 32 or 64 bit. We used 64 bit so our directory looked like
this:
[DB2]
Description = DB2 Driver
Driver = /opt/IBM/db2/V9.7/lib64/libdb2o.so
FileUsage = 1
DontDLClose = 1
UsageCount = 3
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
B. Create an environmental variable to point at the Driver using either LD_LIBRARY_PATH or
LIBPATH for AIX.
C. Register the driver to UnixODBC:
odbcinst -i -d -f odbcinst.ini
D. Create the ODBC.ini configuration file with an entry for each database name and the driver
name (DB2). We created one for the remote IBM i server and also one for TOOLSDB to use as a
local test:

[sysinam]
Description = Test to DB2
Driver = DB2
[toolsdb]
Description = Test to DB2
2009 IBM Corporation

Driver = DB2

You can 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.

14) Now for the moment of truth- testing the connection!
You can use the isql utility to do this:
isql -v DSN_NAME db_username db_password
Where DSN_NAME is the logical database name from odbc.ini, here it's MYIDB2, and the
userid/password is the IBM i userid/password.
If all works correctly, you should get the connect prompt!
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
If you get an error, likely you may be pointing to the wrong driver name, wrong path, or perhaps
not have your environmental variables set (like running ./db2profile to set up the DB2 environment
or setting LD_LIBRARY_PATH, etc. ). There are several articles on unixodbc.org that are very
helpful and can be found under the Manuals tab, including 'Using DB2 and unixODBC' and 'A
guide to using unixODBC without the GUI'. You can also turn on tracing if needed.

You might also like