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
发布评论
评论(1)
已经解决了