Web2py使用DB2

时间:2012-09-28 23:12:17

标签: python db2 web2py pyodbc unixodbc

有人知道如何使用远程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)')

我错过了什么? 提前谢谢你 基督教

2 个答案:

答案 0 :(得分:1)

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

什么是实例端口? default是50000,但是你没有在connect语句中指定一个。

什么是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实例是否处于活动状态并监听端口(当前未知)

答案 1 :(得分: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

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