Search code examples
pythonsybase-asasqlanydb

sqlanydb query on damaged SQL Anywhere table disconnects connection, produces OperationalError (Communication Error -85)


I was using python and sqlanydb to query a Sybase Anywhere database file. Most queries were working, but any SELECT query involving a particular table:

conn = sqlanydb.connect(**{"uid":"dba", "pwd":"sql", "dbf":"file.db"})
cursor = conn.cursor()
cursor.execute("SELECT ... FROM ...")

resulted in an OperationalError, with the stack trace implicating a Communication Error -85, due to unexpected disconnect.

---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-24-2508c8b04dcc> in <module>()
      1 sql = "SELECT ... FROM ..."
      2 cursor = conn.cursor()
----> 3 cursor.execute(sql)
      4 query_columns = [desc[0] for desc in cursor.description]
      5 rows_by_date = cursor.fetchall()

/.../lib/python3.5/site-packages/sqlanydb.py in execute(self, operation, parameters)
    788 
    789     def execute(self, operation, parameters = ()):
--> 790         self.executemany(operation, [parameters])
    791 
    792     def callproc(self, procname, parameters = ()):

/.../lib/python3.5/site-packages/sqlanydb.py in executemany(self, operation, seq_of_parameters)
    759                 operation = operation.encode(self.char_set)
    760             self.new_statement(operation)
--> 761             bind_count = self.api.sqlany_num_params(self.stmt)
    762             self.rowcount = 0
    763             for parameters in seq_of_parameters:

/.../lib/python3.5/site-packages/sqlanydb.py in __stmt_get(self)
    693             self.handleerror(InterfaceError, "no statement")
    694         elif not self.__stmt:
--> 695             self.handleerror(*self.parent.error())
    696         return self.__stmt
    697 

/.../lib/python3.5/site-packages/sqlanydb.py in handleerror(self, errorclass, errorvalue, sqlcode)
    687         if errorclass:
    688             eh = self.errorhandler or standardErrorHandler
--> 689             eh(self.parent, self, errorclass, errorvalue, sqlcode)
    690 
    691     def __stmt_get(self):

/.../lib/python3.5/site-packages/sqlanydb.py in standardErrorHandler(connection, cursor, errorclass, errorvalue, sqlcode)
    377             cursor.messages.append(error)
    378     if errorclass != Warning:
--> 379         raise errorclass(errorvalue,sqlcode)
    380 
    381 

OperationalError: (b'Communication error', -85)

Solution

  • [answer from Richard C Yeh:]
    I gave up and replaced the file with a backup copy, and the problem went away. I speculate that somehow the table had gotten damaged.