更新时间:2021-10-31 21:44:34
这似乎是pymssql的is_disconnect()方法中的错误,它忽略了TCP连接和超时失败,使光标处于不满意的状态;参见 http://www.sqlalchemy.org/trac/ticket/2172 .现在,您可以按照以下方式进行猴子补丁:
This seems to be a bug in the is_disconnect() method for pymssql where it ignore TCP connection and timeout failures, leaving the cursor in an unhappy state; see http://www.sqlalchemy.org/trac/ticket/2172. For now, you can monkey-patch as:
from sqlalchemy.dialects.mssql import pymssql
def is_disconnect(self, e):
for msg in (
"20003",
"20004",
"Error 10054",
"Not connected to any MS SQL server",
"Connection is closed"
):
if msg in str(e):
return True
else:
return False
pymssql.MSDialect_pymssql.is_disconnect = is_disconnect