I'm using pyodbc to connect to my SQL server. My scripts run most of the times as expected but sometimes I get either of these 3 errors when the script is executing a command with the SQL database:
pyodbc.Error: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure (0) (SQLExecDirectW)')
pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()). (10054) (SQLExecDirectW)')
pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (recv()). (10054) (SQLExecDirectW)')
What can I do to prevent this?
Edit: Actual commands in my script are really very basic ones so I didn't mention it in my original post.
import pyodbc
connectionString1 = 'x'
connection1 = pyodbc.connect(connectionString1)
cursor1 = connection1.cursor()
query1 = '''
SELECT/UPDATE ...
'''
cursor1.execute(query1)
res = cursor1.fetchall()
# do some operations using res
connection1.commit()
sqlalchemy.exc.OperationalError:
I have the same problem today because the length of the field is not enough relative to the length of the data. Lengthening the length of the field will solve the problem.