1. 程式人生 > >sql error: (’08S01′, ‘[08S01] [Microsoft][ODBC Driver 13 for SQL Server]Communication link failure (0) (SQLExecDirectW)’)

sql error: (’08S01′, ‘[08S01] [Microsoft][ODBC Driver 13 for SQL Server]Communication link failure (0) (SQLExecDirectW)’)

在使用pyodbc 從 python 連到 MSSQL 時,當有一個 thread 固定在 polling database 裡的值,但每次連database 不是重新建立 connection 而是沿用 global 的 connection,在重啟 sql server 時可以遇到這個 Error.

('08S01', '[08S01] [Microsoft][ODBC Driver 13 for SQL Server]Communication link failure (0) (SQLExecDirectW)')

如果是去取得 table 物件,會遇到這一個 Error:

 ('08S01', '[08S01] [Microsoft][ODBC Driver 13 for SQL Server]Communication link failure (0) (SQLTables)'

python 2.7 – How to re-establish connection after communication link failure with pyodbc?

Per my experience, I think may be you can try to use the code below to implement the retry logic.

import time

retry_flag = True
retry_count = 0
while retry_flag and retry_count < 5:
  try:
    cursor
.execute(query, [args['type'], args['id']]) retry_flag = False except: print "Retry after 1 sec" retry_count = retry_count + 1 time.sleep(1)

相關文章: