Question

I use Oracle ODP.NET connector to connect to Oracle database server.

The problem is a connection sometimes is lost due to several different problems (like network failure or server forcibly closes a connetion by peer). This causes an uncaught exception because I cannot catch exceptions while a connection object is not used in a query or during an idle time of an application.

The question is how can I catch Oracle connection exceptions when a connection is lost? Is there any callback technique or something that can inform me about disconnection?

Was it helpful?

Solution

See my comment above about Validate Connection = true in the connection pool connect string.

You can also write your own "connection tester" routine that does a "Select sysdate from dual" against the database to test the connection.

Both of these solutions cost a roundtrip to the database. Neither of these solutions completely prevent network errors as they can happen right after you test it.

Bottom line is you need to be catching exceptions anytime you use an ODP.NET object if you don't want an unhandled exception.

There's no callback mechanism available that will prevent this.

I don't really understand how you seem to be saying you are getting exceptions when you are not using the odp.net objects. If you are getting an exception, you must be using the odp.net object at that moment and therefore you can catch the exception in that code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top