Re: [cx-oracle-users] How to deal with lost connection to Oracle ?
Brought to you by:
atuining
From: Christopher J. <chr...@or...> - 2010-07-26 18:53:50
|
On 07/21/2010 10:50 AM, Anthony Tuininga wrote: >>> On Wed, Jul 21, 2010 at 7:14 AM,<prz...@po...> wrote: >>>> Each Oracle has its own backup time. What I need is to >>>> properly handle lost connections , e.g.: >>>> minute 1: fetch data >>>> minute 2: fetch data >>>> minute 3: fetch data >>>> minute 4: lost connection [1] (how to detect it ?) - backup started >>>> minute 5: try to connect - failed [2] (how to detect it ?) - ongoing backup process >>>> minute 6: try to connect - failed ... >>>> minute 7: try to connect - failed ... >>>> minute 8: try to connect - failed ... >>>> minute 9: try to connect - successful ... >>>> minute10: fetch data >>>> >>>> How can I detect [1] and [2] ? >>> >>> It depends what version of Oracle you are using. For 10.2 and up you >>> can use connection.ping() which will attempt to contact the server and >>> raise an error if the connection has dropped. >>> >>> try: >>> connection.ping() 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. Chris PS. Off topic (but of interest to Python & Oracle users) is a free, online Oracle Tuxedo training event includes a hands-on Python lab. Learn more at http://www.oracle.com/goto/otnvdd The American-time zone lab is tomorrow. -- Email: chr...@or... Tel: +1 650 506 8630 Blog: http://blogs.oracle.com/opal/ Free PHP Book: http://tinyurl.com/ugpomhome |