2012-09-28 86 views
2

有人知道如何使用遠程DB2服務器在Linux上運行Web2py?Web2py與DB2一起工作

我試着用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)') 

我缺少什麼? 在此先感謝
基督教

+0

您有沒有使用DAL的原因? http://web2py.com/books/default/chapter/29/06 – korylprince

+0

即時通訊使用Web2py DAL,但它沒有直接的Db連接,而是你需要f/e pyodbc這個 – chespinoza

+0

所以使用連接字符串「db2: //用戶名:密碼@測試「不起作用? – korylprince

回答

1

這是一個典型的通信問題錯誤。 連接之前,請嘗試檢查連接:

什麼是實例端口?默認值是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實例是否處於活動狀態並監聽端口(當前未知)

+0

網絡通信完成後,我只能通過telnet連接,使用pyodbc我得到了同樣的錯誤 – chespinoza

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 

我提到這一點,因爲我認爲你錯過了在配置文件中的一些信息。

相關問題