对损坏的SQL Anywhere表的sqlanydb查询断开连接,产生OperationalError(通信错误-85)

时间:2017-01-10 16:27:14

标签: python sybase-asa sqlanydb

我使用python和sqlanydb来查询Sybase Anywhere数据库文件。大多数查询都有效,但涉及特定表的任何SELECT查询都是:

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

导致一个OperationalError,由于意外断开,堆栈跟踪意味着通信错误-85。

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

1 个答案:

答案 0 :(得分:0)

[Richard C Yeh回答:] 我放弃了并用备份副本替换了文件,问题就消失了。我推测桌子不知何故已经损坏了。