From:       To:      
Home > Documentation > IBM DB2

How to Connect to IBM DB2 Database

When Intelligent Converters software is installed on the same machine where IBM DB2 server is running, all is set and migration tool can be used right away. Otherwise, it is necessary to install and configure IBM client software. Basically there are two variations of DB2 client: IBM Data Server Driver/Runtime/Client and IBM CLI Driver.

Configure connection via IBM Data Server Driver/Runtime/Client

All these variations of DB2 client software include command line processor and can be configured by running the following DB2 command:

db2 catalog tcpip node nodename remote hostname server service_name

Where:

nodename
Local alias for the node to be cataloged.
hostname
Host name or IP address of the node where the target database resides. The maximum length of this parameter is 255 characters.
service_name
Service name (case sensitive!) or the port number of the server database manager instance. The maximum length of this parameter is 14 characters. If a service name is specified, the services file on the client is used to map the service name to a port number. The port number on the client and the server must match.

You can verify that all parameters were specified correctly by running the following statements:

db2 attach to nodename user username using password
db2 list applications
db2 detach

Where:

nodename
Name of the instance to attach.
username
Authentication identifier registered on the target DB2 server
password
Password for the user name

Configure connection via IBM DB2 CLI and ODBC drivers

There are two ways of configuring connection for IBM DB2 CLI and ODBC drivers - via settings in db2cli.ini or db2dsdriver.cfg configuration files. These files must be located in "cfg" subfolder of the driver installation. When connection settings are specified using both options, they are used in the following order:

This is example of db2cli.ini for connection to database "db1" running on host 11.22.33.44 with opened port 56789:

[db1]
Database=db1
Protocol=tcpip
Hostname=11.22.33.44
Servicename=56789

And here is example of db2dsdriver.cfg for connection to database "sample" running on host server.domain.com with opened port 333:

<configuration>
  <dsncollection>
    <dsn alias="myDSN" name="sample" host="server.domain.com" port="11111">
    </dsn>
  </dsncollection>
  <databases>
    <database name="sample" host="server.domain.com" port="333">
      <parameter name="CommProtocol" value="TCPIP"/>
      <parameter name="UID" value="username"/>
    </database>
  </databases>
</configuration> 

Have questions? Contact us