rajeshveerepalli / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Not clear error when conection lost #173

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. connect to db ( client machine to server )
2. crash server/db or unplug client/server from the web
3. try a query

What is the expected output? What do you see instead?
  A clear connection error

What version of the product are you using? On what operating system?
  pyodbc-2.1.8-py2.6

Please provide any additional information below.

it can be solved if add this code inside pyodbc:

try:
  doQuery( strquery, args )
except:
  try:
    #dummy query to check connection
    doQuery( 'select 1 as [a]', args )
    raise original error
  except:
    raise connection error

if dummy query fail it must be connection error

Original issue reported on code.google.com by filosde...@gmail.com on 29 Apr 2011 at 12:35

GoogleCodeExporter commented 8 years ago
I don't this is something I can do, considering some potential side effects.

You may consider examining the SQLSTATE that is part of the original error to 
see if it is consistent.  Your database give you a consistent error for this 
condition.  (What database are you using and what error do you get?)

However, it would be very easy for you to wrap the cursor class and do exactly 
what you show here.  The easiest way to is to create a new class that holds a 
native cursor and passes all _getattr_ calls to it except for execute.  If you 
need an example, let me know.  Perhaps I should add a wiki page for this.

Original comment by mkleehammer on 20 May 2011 at 7:26