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

发布于 2024-11-11 18:27:34 字数 1332 浏览 6 评论 0原文

我想使用 IBM DB2 ODBC 驱动程序将 Python 连接到 DB2 版本 9.1。

以下是我将 Python 连接到 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")

我的问题是,我的 IBM DB2 版本是 9.1,没有 FixPack,当我尝试连接到 IBM DB2 9.1 版本时收到错误消息。

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

对此错误的解释写在页面 http://programmingzen.com/2008/02/08/essential-guide-to-the-ruby-driver-for-db2/is: “如果出现此错误,通常意味着您使用的 DB2 版本太旧。安装最新的 FixPack 或最新版本的 DB2(当前为 9.5)来解决问题。”

但我无法安装最新的 FixPack 或最新版本的 DB2,也无法以任何方式修改现有的 DB2 安装。

问题

有什么方法可以在不修改数据库的情况下连接到 DB2 版本 9.1,可能使用 IBM_DB 之外的其他东西?

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 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][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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花辞树 2024-11-18 18:27:34

我认为问题出在客户端 ibm_db 驱动程序中。基本上,您可以连接到所有语言的任何旧版本。尝试获取另一个 db2 驱动程序。如果我是你,我会安装 db2 客户端,它附带了几个位于 sqllib 中的驱动程序。

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.

绅士风度i 2024-11-18 18:27:34

您使用的 ibm_db 版本是什么?我可以毫无问题地使用 ibm_db 1.0.4 连接到 DB2 9.1。

另外:基于您在连接字符串中指定 DSN 的事实,我假设您已经在客户端上将数据库编目为 PDB2。您可以将 connect 语句简化为:

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

唯一一次您需要使用较长的形式(在其中指定 DATABASE/ PORT/HOST/UID/PWD) 是指您是否使用无 DSN 连接(即数据库尚未在本地计算机上编目)。

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).

樱花坊 2024-11-18 18:27:34

我猜您的 DB2 客户端 API 版本高于 DB2 服务器本身,请确保您在客户端计算机上使用相同的版本,尝试使用 DB2 控制中心远程连接和维护数据库,并尝试从 python 连接:

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

AFAIK,这将强制包装器使用本机库而不是 odbc。

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.

我的黑色迷你裙 2024-11-18 18:27:34

ibm_db(和 PyDB2 只是 Python 模块,允许您通过 python 访问 DB2 API 调用。DB2查询本身是由您的 DB2 安装执行的...与 ibm_db 和 PyDB2 非常不同的东西

听起来像是您的 DB2 安装有问题,而不是 ibm_db 您可以通过从命令行运行 db2 并查看是否可以执行来测试这一点。直接在 db2 命令行界面中查询。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文