Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to reconnect when a network error occurs (connection is lost)

678331Jan 6 2009 — edited Jan 7 2009
I'm just curious about how to recover from a network error or similar errors.
This link better explain my problem, but it does not apply to Oracle DBs

Here is what I do:

I Have established a working connection to the database, and pooling is enabled
Everything works as it should, but when I pull my network cable I get an exception:
ORA-12571: TNS:packet writer failure

Here is my code:

{color:#0000ff}try
{
cmd.Prepare();
if (reader != null)
reader.Dispose();
reader = cmd.ExecuteReader(); // it is this call that throws the exception
reader.FetchSize = cmd.RowSize * 100;
}

catch (OracleException e)
{
String st = Connection.State.ToString();
throw e;
}{color}

Here is what I want to do:

In the catch part I would like to try and reconnect say 5 times before giving up
I can see that even though I've lost my network connection the Connection.State is set to open.

What is the best way of doing this, so that the application reconnects from within the catch?

Edited by: user10763840 on Jan 6, 2009 3:10 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2009
Added on Jan 6 2009
2 comments
1,429 views