我正在尝试通过 ibm_db 模块使用 Python 访问我的 Informix 数据库。
我正在跑步:
这是我到目前为止的代码:
import os
# apparently I need to add the clipdriver dll before importing ibm_db
os.add_dll_directory('path_to_clidriver')
import ibm_db
cnx_string = 'DATABASE=database_name;HOSTNAME=hostname.com;PORT=9088;PROTOCOL=tcpip;UID=user;PWD=123;'
try:
conn = ibm_db.connect(cnx_string, "", "")
print("Connected successfully!")
except Exception as e:
print(f"Unable to connect: {e}")
exit()
ibm_db.close(conn)
这是我重新调整的错误消息:
Unable to connect: [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: "119.82.149.212". Communication function detecting the error: "recv". Protocol specific error code(s): "*", "*", "0". SQLSTATE=08001 SQLCODE=-30081
PS G:\My Drive\Python\ibm-db>
Informix 服务器必须配置为提供 DRDA 协议,该协议允许 python imb_db 使用的 clidriver 进行操作。
您的 MS Windows 设备还必须在其软件防火墙中为入站和出站 TCP 流量打开指定的端口号。