开发者

How to use IBM_DB with older versions of DB2?

I want to connect Python to DB2 version 9.1 using IBM DB2 ODBC Driver.

Following is my code to connect Python to DB2. This program is working in the later versions of IBM DB2.

import ibm_db

conn = ibm_db.connect("DSN=PDB2;DRIVER={IBM DB2 ODBC DRIVER};DATABASE=MDBASIS;PORT=1234;PROTOCOL=TCPIP;UID=username;PWD=password","","")
stmt = ibm_db.exe_immediate(conn,"create table egg (ID SMALLINT, NAME VARCHAR(30))")
stmt = ibm_db.exe_immediate(conn,"insert into egg (ID, NAME) VALUES('1','ok')")
state = ibm_db.exe_immediate("select * from egg")
result = ibm_db.fetch_both(state)
while result != False:    
    print 'id = %d and name = %s' %(result[0],result[1])
    result = ibm_db.fetch_both(state)
stmt = ibm_db.exe_immediate(conn,"drop table egg")

My prob开发者_JAVA技巧lem is, the version of my IBM DB2 is 9.1 without FixPack and I get an error message when I try to connect to IBM DB2 9.1 version.

"[IBM][CLI Driver] CLI0133E Option type out of range. SQLSTATE=HY092 SQLCODE=-99999"

And the explanation for this error written in page http://programmingzen.com/2008/02/08/essential-guide-to-the-ruby-driver-for-db2/is: "If you get this error, it usually means that you are using a version of DB2 that is too old. Install the latest FixPack or the latest version of DB2 (currently 9.5) to resolve the problem."

But I cannot install latest FixPack or the latest version of DB2 or in any way modify existing DB2 installation.

Question

Is there any way I can connect to DB2 version 9.1 without modifying the database, possibly using something else than IBM_DB?


I think the problem is in the client ibm_db driver. Basically you can connect to any older version from all the languages. Try to get another db2 driver. If I were you I would install the db2 client which comes with several drivers which are located in sqllib.


What version of ibm_db are you using? I am able to connect to DB2 9.1 with ibm_db 1.0.4 without problems.

Also: Based on the fact that you're specifying DSN in your connection string, I assume that you already have the database cataloged on the client as PDB2. You can greatly simply your connect statement to:

conn = ibm_db.connect('PDB2','username','password')

The only time you need to use the longer form (where you specify DATABASE/PORT/HOST/UID/PWD) is if you are using a DSN-less connection (i.e. the database has not been cataloged on the local machine).


I guess your DB2 client API version is higher than the DB2 server itself, ensure you use the same version on the client machine, try to connect and maintain your database remotely using the DB2 control center, and try to connect from python with:

conn = ibm_db.connect("MDBASIS", "username", "password")

AFAIK, this would force the wrapper to use native library instead of odbc.


ibm_db (and PyDB2 are just python modules that allow you to access the DB2 API calls through python. The DB2 queries themselves are being performed by your DB2 installation... something very separate from ibm_db and PyDB2.

It sounds like your DB2 installation is the problem, not ibm_db. You can test this by running db2 from the command line and seeing if you can execute your query directly in the db2 command line interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜