使用的命令:
server=XX.XX.XX.XX
user=infodict['user'] #用户名
password=infodict['password'] #密码
database=infodict['database'] #数据库名称
conn = pymssql.connect(server,user,password,database)
遇到的问题:
OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (XX.XX.XX.XX)\nNet-Lib error during Unknown error (10061)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (XX.XX.XX.XX)\nNet-Lib error during Unknown error (10061)\n')
排查原因:
1.使用的pymssql的版本,1.x和2.x的参数不一样,需要注意host的使用方式,官方文档有说明。官网文档:https://pymssql.readthedocs.io/en/latest/migrate_1_x_to_2_x.html
2.检查Sql Server配置管理工具的配置中,TCP/IP是否为禁用状态。(SQL Native Client 11.0 Configuration和SQL Server Network Configuration都检查下)
如果是disabled,修改为Enabled,重启SQL Server Service即可。
修改SQL Native Client 11.0 Configuration配置,
修改SQL Server Network Configuration配置,
重启service,
转载请注明出处~