[win32 SQLServer] connection lost detection
The pyodbc driver when connected to SQLServer 2005 reports lost connections in
a quite strange way, raising a pyodbc.Error exception with a specific exc.args value.
This patch catches these and reconnect properly.
--- a/server/sources/native.py Sat May 29 10:03:50 2010 +0000
+++ b/server/sources/native.py Sat May 29 10:06:07 2010 +0000
@@ -442,6 +442,15 @@
self.warning("trying to reconnect")
session.pool.reconnect(self)
cursor = self.doexec(session, sql, args)
+ except (self.DbapiError,), exc:
+ # We get this one with pyodbc and SQL Server when connection was reset
+ if exc.args[0] == '08S01':
+ self.warning("trying to reconnect")
+ session.pool.reconnect(self)
+ cursor = self.doexec(session, sql, args)
+ else:
+ raise
+
results = self.process_result(cursor, cbs)
assert dbg_results(results)
return results
--- a/server/sqlutils.py Sat May 29 10:03:50 2010 +0000
+++ b/server/sqlutils.py Sat May 29 10:06:07 2010 +0000
@@ -165,6 +165,7 @@
dbapi_module = self.dbhelper.dbapi_module
self.OperationalError = dbapi_module.OperationalError
self.InterfaceError = dbapi_module.InterfaceError
+ self.DbapiError = dbapi_module.Error
self._binary = dbapi_module.Binary
self._process_value = dbapi_module.process_value
self._dbencoding = dbencoding