Handle TCP Provider: Error code 0x68 (104)

2024/10/7 0:22:31

I'm using this code to sync my db with the clients:

    import pyodbcSYNC_FETCH_ARRAY_SIZE=25000# define connection + cursorconnection = pyodbc.connect()cursor = connection.cursor()query = 'select some_columns from mytable'cursor.execute(query)while True:rows = cursor.fetchmany(SYNC_FETCH_ARRAY_SIZE) # <<< error hereif not rows:breakinsert_to_our_db(rows)cursor.close()

I'm getting the below error intermitently:

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)')

How should i handle this error? Is this an error on the connection (thus i need to close and recreate the connection) or on the cursor and i simply need to add a retry?

I will add the below to retry (in place of the line throwing the error), is this enough to solve the issue? Will retries have any effect at all if im experiencing a tcp error?

MAX_RETRIES=5def get_rows(retry_count=0):"""Wrapper function to add retry functionality to fetchmany"""try:rows = sg_cur.fetchmany(SYNC_FETCH_ARRAY_SIZE)except Exception as e:if retry_count >= MAX_RETRIES:raise ConnectionError(f'fetchmany caused the error: {e}')else:logger.debug(f'Error in get_rows: {e}, attempt: {retry_count}/{MAX_RETRIES}')retry_count += 1return get_rows(retry_count=retry_count)return rows

Edit:

There is an issue open on github for this. In the meantime what would be a viable workaround?

  • Store the last read after insert_to_our_db in our db then restart from there in case of a bug
  • just run the entire process again

Notes:

  • The error is intermittent, thus hard to test
  • I'm syncing a large table from a client's db on a different host. Thus i need to update/insert all rows at once to be sure that the data is current
  • I cant make changes to the client's db
Answer

try this:

sudo ifconfig eth0 mtu 1350
https://en.xdnf.cn/q/70301.html

Related Q&A

vectorized radix sort with numpy - can it beat np.sort?

Numpy doesnt yet have a radix sort, so I wondered whether it was possible to write one using pre-existing numpy functions. So far I have the following, which does work, but is about 10 times slower tha…

Which library should I use to write an XLS from Linux / Python?

Id love a good native Python library to write XLS, but it doesnt seem to exist. Happily, Jython does.So Im trying to decide between jexcelapi and Apache HSSF: http://www.andykhan.com/jexcelapi/tutoria…

put_records() only accepts keyword arguments in Kinesis boto3 Python API

from __future__ import print_function # Python 2/3 compatibility import boto3 import json import decimal#kinesis = boto3.resource(kinesis, region_name=eu-west-1) client = boto3.client(kinesis) with ope…

Setting a transparent main window

How to set main window background transparent on QT? Do I need an attribute or a style? Ive tried setting the opacity, but it didnt work for me. app.setStyleSheet("QMainWindow {opacity:0}"

Elementwise division of sparse matrices, ignoring 0/0

I have two sparse matrices E and D, which have non-zero entries at the same places. Now I want to have E/D as a sparse matrix, defined only where D is non-zero.For example take the following code:impor…

Django import export Line number: 1 - uColumn id not found

I am trying to import excel documents into a Django DB. I have added the following code to admin.py and model.py. There seems to be an error in the development of Django. I have read through several di…

Why cant I access builtins if I use a custom dict as a functions globals?

I have a dict subclass like this:class MyDict(dict):def __getitem__(self, name):return globals()[name]This class can be used with eval and exec without issues:>>> eval(bytearray, MyDict()) <…

How to enable autocomplete (IntelliSense) for python package modules?

This question is not about Pygame, Im usin Pygame as an example.While experimenting with Pygame Ive noticed that autocomplete is not working for some modules. For example, if I start typing pygame.mixe…

Integrating a redirection-included method of payment in django-oscar

I am developing a shopping website using django-oscar framework, in fact I am using their sandbox site. I want to add payment to the checkout process, but the thing is, I am totally confused!Ive read t…

How can I unpack sequence?

Why cant I do this:d = [x for x in range(7)] a, b, c, d, e, f, g = *dWhere is it possible to unpack? Only between parentheses of a function?