简体   繁体   English

如何将 IBM_DB 与旧版本的 DB2 一起使用?

[英]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.我想使用 IBM DB2 ZF89750C5A8C9725AE4FB85B86EC70Z 版本 9.1 将 Python 连接到 DB2 版本 9.1。

Following is my code to connect Python to DB2.以下是将 Python 连接到 DB2 的代码。 This program is working in the later versions of IBM DB2.该程序在 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 problem 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 DB2 的版本是 9.1,没有 FixPack,当我尝试连接到 IBM DB2 9.1 版本时收到错误消息。

"[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."此错误的解释写在http://programmingzen.com/2008/02/08/essential-guide-to-the-ruby-driver-for-db2/is页中:“如果您收到此错误,通常表示您使用的 DB2 版本太旧。安装最新的 FixPack 或最新版本的 DB2(当前为 9.5)来解决问题。

But I cannot install latest FixPack or the latest version of DB2 or in any way modify existing DB2 installation.但我无法安装最新的 FixPack 或最新版本的 ZC890515AE4FB85B86EC70Z 或以任何方式修改现有的 DB2 安装。

Question问题

Is there any way I can connect to DB2 version 9.1 without modifying the database, possibly using something else than IBM_DB?有什么方法可以在不修改数据库的情况下连接到 DB2 9.1 版,可能使用 IBM_DB 以外的其他东西?

I think the problem is in the client ibm_db driver.我认为问题出在客户端 ibm_db 驱动程序中。 Basically you can connect to any older version from all the languages.基本上,您可以连接到所有语言的任何旧版本。 Try to get another db2 driver.尝试获取另一个 db2 驱动程序。 If I were you I would install the db2 client which comes with several drivers which are located in sqllib.如果我是你,我会安装 db2 客户端,它带有几个位于 sqllib 中的驱动程序。

What version of ibm_db are you using?您使用的是哪个版本的 ibm_db? I am able to connect to DB2 9.1 with ibm_db 1.0.4 without problems.我可以毫无问题地使用 ibm_db 1.0.4 连接到 DB2 9.1。

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.另外:基于您在连接字符串中指定 DSN 的事实,我假设您已经在客户端上将数据库编目为 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 (ie the database has not been cataloged on the local machine).唯一需要使用较长格式(指定 DATABASE/PORT/HOST/UID/PWD)的情况是您使用的是无 DSN 连接(即数据库尚未在本地计算机上编目)。

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: 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. AFAIK,这将强制包装器使用本机库而不是 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. 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.听起来您的 DB2 安装是问题,而不是 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.您可以通过从命令行运行 db2 并查看是否可以直接在 db2 命令行界面中执行查询来测试这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM