2

有人知道如何使用远程 DB2 服务器在 Linux 上运行 Web2py 吗?

我尝试使用 pyodbc,但它的文档很差

我找不到它的分步指南。

我的配置文件:

odbcinst.ini:

[DB2]
Description     = DB2 Driver
Driver          = /opt/odbc_cli/clidriver/lib/libdb2.so
FileUsage       = 1
DontDLClose     = 1

odbc.ini

[test]
Description     = Test to DB2
Driver          = DB2

尝试连接:

>>> import pyodbc
>>> cnxn = pyodbc.connect('DRIVER={DB2};SERVER=172.16.1.35;DATABASE=log10;UID=db2admin;PWD=passs')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('08001', '[08001] [unixODBC][IBM][CLI Driver] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "127.0.0.1".  Communication function detecting the error: "connect".  Protocol specific error code(s): "111", "*", "*".  SQLSTATE=08001\n (-30081) (SQLDriverConnect)')

我错过了什么?在此先感谢
基督教

4

2 回答 2

1

这是典型的通信问题错误。在连接之前,请尝试检查连接性:

什么是实例端口?默认值为 50000,但您未在连接语句中指定 1。

什么是 IP 地址/主机名?如果您的情况似乎是 172.16.1.35

在该端口尝试 telnet

telnet 172.16.1.35 50000

如果可以建立连接,您将收到如下消息:

Trying 172.16.1.35...
Connected to hostname.
Escape character is '^]'.

如果您有连接问题,您将看到

Trying 172.16.1.35...
telnet: Unable to connect to remote host: Connection refused

据我所知,您必须在执行程序之前检查实例端口和连接设置。可能是防火墙问题,您是否检查了打开的端口?在服务器中尝试 netstat -nato,查看 DB2 实例是否处于活动状态并监听端口(目前未知)

于 2012-09-29T16:32:57.843 回答
1

我使用 PHP 连接到远程 DB2 服务器,这就是我的 /etc/odbc.ini 文件的样子:

[primary]
Description             = primary
Driver                  = iseries
System                  = xxx.xxx.xxx.xxx
UserID                  = xxxxxxxxxx
Password                = xxxxxxxxxx
Naming                  = 0
DefaultLibraries        = QGPL
Database                = XXXXXXXXXX
ConnectionType          = 0
CommitMode              = 2
ExtendedDynamic         = 0
DefaultPkgLibrary       = QGPL
DefaultPackage          = A/DEFAULT(IBM),2,0,1,0,512
AllowDataCompression    = 1
LibraryView             = 0
AllowUnsupportedChar    = 0
ForceTranslation        = 0

我的 /etc/odbcinst.ini 文件如下所示:

[iseries]
Description     = iSeries Access for Linux ODBC Driver
Driver          = /usr/lib/libcwbodbc.so
Setup           = /usr/lib/libcwbodbcs.so
NOTE1           = If using unixODBC 2.2.11 or later and you want the 32 and 64-bit ODBC drivers to share DSN's,
NOTE2           = the following Driver64/Setup64 keywords will provide that support.
Driver64        = /usr/lib/lib64/libcwbodbc.so
Setup64         = /usr/lib/lib64/libcwbodbcs.so
Threading       = 2
DontDLClose     = 1
UsageCount      = 1

我提到这一点是因为我认为您在配置文件中缺少一些信息。

于 2012-10-02T18:09:41.360 回答