Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

Error connecting from Python to Db2 through pyodbc

I installed the Db2 ODBC driver in Windows 10 following these instructions. I extracted the driver folder in C:oolsdb2cli and run db2cli install -setup from the bin folder.

This seems to have worked fine, as the ODBC driver was registered in Windows:

enter image description here

But when I try to connect from Jupyter I get this error:

server = 'localhost' 
database = 'mydb' 
username = 'db2inst1' 
password = 'abc123' 
driver = 'IBM DB2 ODBC DRIVER - C_tools_db2cli'
conn = pyodbc.connect('DRIVER={' + driver +'};SERVER='
         + server + ';DATABASE=' + database + ';UID=' 
         + username + ';PWD=' + password + ';PROTOCOL=TCPIP;PORT=50000' )

Error Traceback (most recent call last) in 4 password = 'abc123' 5 driver = 'IBM DB2 ODBC DRIVER - C_tools_db2cli' ----> 6 conn = pyodbc.connect('DRIVER={' + driver +'};SERVER=' 7 + server + ';DATABASE=' + database + ';UID=' 8 + username + ';PWD=' + password + ';PROTOCOL=TCPIP;PORT=50000' )

Error: ('HY000', '[HY000] [IBM][CLI Driver] SQL1042C An unexpected system error occurred. SQLSTATE=58004 (-1042) (SQLDriverConnect); [HY000] [IBM][CLI Driver] SQL1042C An unexpected system error occurred. SQLSTATE=58004 (-1042)')

I unsuccessfully tried to find the error codes to find a solution. What should be looked at to fix this problem?

Note: I added C:oolsdb2cliin to the PATH but still get the same error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This issue was caused by a defect in clidriver for some specific configurations on Microsoft Windows.

You can workaround this by ensuring that the PATH does not have any other Db2-products on it (except for clidriverin), and then ensuring to add two additional directories to the PATH before launching python. These are the fully qualified pathnames to these directories:

clidriverinicc64
clidriverinamd64.vc12.crt

IBM should at some point deliver a fix for IT34327.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...