[win32 SQLServer] connection lost detection stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Sat, 29 May 2010 10:06:07 +0000
branchstable
changeset 5605 2604545d7dd9
parent 5604 60a92bf32a18
child 5606 61b28589d33f
child 5637 b72a838aa109
[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.
server/sources/native.py
server/sqlutils.py
--- 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