Tinniam V. Ganesh
Tinniam V. Ganesh

Reputation: 2077

Connecting to DB2 with pyodbc on Linux

I am trying to connect DB2 with pyodbc on linux and I get the error

"('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'IBM DB2 ODBC Driver' : file not found (0) (SQLDriverConnect)")## Heading ##

Is there some installation required or am I missing path?

# Create a connection object
cnxn = pyodbc.connect(
    'Driver={IBM DB2 ODBC Driver}; '
    'Hostname=nn.nn.nnn.nnn; '
    'Port=50000; '
    'Protocol=TCPIP; '
    'Database=myDB; '
    'CurrentSchema=myschema; '
    'UID=user1; '
    'PWD =test1;'
    )

I tried to configure by following the link at https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.cli.doc/doc/t0061216.html

I did a yum install unixODBC

But I could not find the path where libdb2.so was installed for configuring odbcinst.int as given here https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.cli.doc/doc/t0061216.html

What is the path for libdb2.so?

Upvotes: 2

Views: 1512

Answers (1)

mao
mao

Reputation: 12267

The driver-manager (unixODBC) does not supply a driver for the Db2 rdbms. Normally you will use a Db2-driver supplied by IBM which works with unixODBC.

If your Db2-server is remote from Linux then you need to install Db2 driver separately and configure it.

If your Db2-server is already installed locally on Linux, then it includes a local Db2-client already, and libraries are symlinked from the Db2-instance home directory sqllib/lib64 directory ( for example /home/db2inst1/sqllib/lib64 will contain the symlinks to the relevant libraries, if your Db2-instance is called "db2inst1"). In this case you don't need to install anything else.

Otherwise, there are various IBM supplied Db2-clients, so you have to choose the right one, which depends both on your Db2-server platform and your programming needs (different footprints for different drivers). There are also third party drivers, not mentioned here. See here for Db2 client types: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.5.0/com.ibm.swg.im.dbclient.install.doc/doc/c0022612.html

[ 1 ] If your remote Db2-server runs on Linux/Unix/Windows/zLinux then download your IBM driver from Passport Advantage (choose the latest driver version for your Db2-server version). Your Db2 DBA (if you have one) should also have an installable copy although it's always wise to download the latest version from Passport Advantage website as long as you have that access.

If your Db2-server runs on Z/OS or i-Series AND your company already has a Db2-connect gateway server installed and configured then you can use the same driver as [1] above. The Db2-connect gateway is a separate hostname that does the protocol conversion (if necessary) and allows easier licensing at a price.

If your remote Db2-server runs on i-Series (formerly OS/400) and your company is not using a Db2-connect gateway, ask your i Admin for the correct driver and install that on Linux. For i-Series you can either use a driver from IBM or from a third party, as long as it supports ODBC/CLI on Linux for your version and bitness.

If your Db2-server runs on Z/OS and your company does not use a Db2-connect gateway (i.e. instead you are connecting directly from Linux to Db2-for-Z/OS) then you will need to use the same driver as in [1] but additionally apply a suitable license file to your Linux Db2 driver. Your admin should know the details.

Upvotes: 4

Related Questions