Re: [cx-oracle-users] How to deal with lost connection to Oracle ?
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2010-07-26 19:20:07
|
> If you (i) can't use ping (ii) find its internal implementation > doesn't catch everything you classify as a connection error (iii) or > don't want to use it because it causes a roundtrip to the DB and hence > reduces scalability, then you could try explicitly testing error > codes. A fairly good set of codes to identify if an error is a > connection error is given in the PHP_OCI_HANDLE_ERROR macro used by > PHP error checking. See > http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/oci8/php_oci8_int.h?view=markup > There's an OCI attribute check (also used in PHP_OCI_HANDLE_ERROR) > that does this test but cx_Oracle doesn't expose it. That can be fixed. :-) Just to be clear: this attribute is only set __after__ an attempt is made to access the server. So at that point the typical solution would be: try: cursor.execute(some_sql) except cx_Oracle.DatabaseError: if cursor.connection.connected: raise print "*** Server not connected: do something about it!" The other option is to check this attribute when the error is being created and store it on the error object instead -- but I suspect exposing the object on the connection will be more flexible. Comments anyone? Anthony |