我真的会谢,连接了四个小时的server,我终于把python和我的server连接上去了,希望我的教训可以给大家帮助!!!!
错误18456:
pymssql._pymssql.OperationalError: (18456, b"\xe7\x94\xa8\xe6\x88\xb7 ‘sa’ \xe7\x99\xbb\xe5\xbd\x95\xe5\xa4\xb1\xe8\xb4\xa5\xe3\x80\x82DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (localhost)\nDB-Lib error message
20002, severity 9:\nAdaptive Server connection failed (localhost)\n")
错误20009:
File “src\pymssql_pymssql.pyx”, line 652, in pymssql._pymssql.connect
pymssql._pymssql.OperationalError: (20009, b’DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost)\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 (localhost)\nNet-Lib error during Unknown error (10061)\n’)
我开始解决了18456以后,随之而来就是20009错误,这个错误我真的是恨啊啊啊啊啊!好在解决了,听我给你们娓娓道来
代码
import pymssql
conn = pymssql.connect(host='localhost',server='LAPTOP-5RJBJM7N\BESSIE', port='61647', user='sa', password='123456', database='test')
if conn:
print("连接成功!")
conn.close()
解决错误
如果还是没有成功运行,一定就是TCP/IP协议那一块出问题了。检查自己的数据库和启动的协议是不是一致,如果确定没有问题,那就是重启的时候出问题,实在不知道重启哪个,就把sql的全部重启一遍,一定能行!!!!