我正在使用此代码将我的数据库与客户端同步:
import pyodbc
SYNC_FETCH_ARRAY_SIZE=25000
# define connection + cursor
connection = pyodbc.connect()
cursor = connection.cursor()
query = 'select some_columns from mytable'
cursor.execute(query)
while True:
rows = cursor.fetchmany(SYNC_FETCH_ARRAY_SIZE) # <<< error here
if not rows:
break
insert_to_our_db(rows)
cursor.close()
Run Code Online (Sandbox Code Playgroud)
我间歇性地收到以下错误:
File "....py", line 120, in ...
rows = sg_cur.fetchmany(SYNC_FETCH_ARRAY_SIZE)
pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x68 (104) (SQLGetData)')
Run Code Online (Sandbox Code Playgroud)
我应该如何处理这个错误?这是连接上的错误(因此我需要关闭并重新创建连接)还是光标上的错误,我只需要添加重试?
我将添加以下内容来重试(代替抛出错误的行),这足以解决问题吗?如果我遇到 TCP 错误,重试会有任何影响吗?
File "....py", line 120, in ...
rows = sg_cur.fetchmany(SYNC_FETCH_ARRAY_SIZE)
pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver …Run Code Online (Sandbox Code Playgroud)