Python怎么判断sqlserver数据库连接是否断开
Python怎么判断sqlserver数据库连接是否断开?(掉线)
回答:
已经解决了
python">def get_db(): global db
def db_connect():
try:
db = pymssql.connect(server='ip', user='user', password='password', database="database",
timeout=20, autocommit=True)
except Exception as e:
print(e)
else:
return db
if db is None:
db = db_connect()
return db
else:
try:
cursor = db.cursor()
cursor.execute("select getdate()")
cursor.close()
return db
except Exception as e:
print(e)
db=db_connect()
return db
以上是 Python怎么判断sqlserver数据库连接是否断开 的全部内容, 来源链接: utcz.com/a/159614.html