Strange question on .NET and Oracle connection

G

Guest

Hello All,

I am trying to redirect users to a standby webpage in case our application
is down due to database server failure. To facilitate this I am opening a
test connection within a try/catch block in application_beginrequest event of
global.asax and in case the connection could not be established, I am
redirecting the users in the catch block.

Now to the interesting part. I am in the testing phase of this feature.
Since our production and development database server are the same I am using
a different approach to test this. I am running the application from my local
machine's web server and I am unplugging the network jack to simulate the
database server failure which is located at some other place.

So, once I unplug the network jack, the very first request should be
redirected to standy page because techinically the connection to Oracle
should not be established. But surprisingly this request is able to make a
database connection even though there is no network connectivity. When I
tried to debug and see, the execution was going well past the
OracleConnection.open() successfully and not going into the catch loop. But
the next request following this request is going into the catch block and is
redirected. What is the reason behind this strange behavior. Does .NET cache
the OracleConnections?

Here is the code....

System.Data.OracleClient.OracleConnection myDBConn =
new System.Data.OracleClient.OracleConnection();
try
{
myDBConn.ConnectionString =
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
myDBConn.Open();

}
catch(OracleException ex)
{
//Database server is down; Redirect to standby page
}


Thanks a lot!!!
 
G

Guest

I am not sure where the issue is, but I would consider using the global Error
handler instead of setting up a try ... catch. This way all errors can be
redirected by your redirect and you can send the SQL specific exception to a
particular page.

You can also declaratively set up an error redirect in web.config, but this
will not allow you to weed out SQL connection issues.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
P

Paul Clement

¤ Hello All,
¤
¤ I am trying to redirect users to a standby webpage in case our application
¤ is down due to database server failure. To facilitate this I am opening a
¤ test connection within a try/catch block in application_beginrequest event of
¤ global.asax and in case the connection could not be established, I am
¤ redirecting the users in the catch block.
¤
¤ Now to the interesting part. I am in the testing phase of this feature.
¤ Since our production and development database server are the same I am using
¤ a different approach to test this. I am running the application from my local
¤ machine's web server and I am unplugging the network jack to simulate the
¤ database server failure which is located at some other place.
¤
¤ So, once I unplug the network jack, the very first request should be
¤ redirected to standy page because techinically the connection to Oracle
¤ should not be established. But surprisingly this request is able to make a
¤ database connection even though there is no network connectivity. When I
¤ tried to debug and see, the execution was going well past the
¤ OracleConnection.open() successfully and not going into the catch loop. But
¤ the next request following this request is going into the catch block and is
¤ redirected. What is the reason behind this strange behavior. Does .NET cache
¤ the OracleConnections?
¤
¤ Here is the code....
¤
¤ System.Data.OracleClient.OracleConnection myDBConn =
¤ new System.Data.OracleClient.OracleConnection();
¤ try
¤ {
¤ myDBConn.ConnectionString =
¤ System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
¤ myDBConn.Open();
¤
¤ }
¤ catch(OracleException ex)
¤ {
¤ //Database server is down; Redirect to standby page
¤ }
¤

When you open a connection there is a request to the connection pool before attempting to open a new
connection. My guess is that your open statement is using an existing connection from the pool.

You will probably need to do a bit more work in order to determine whether that connection can still
talk to the database.


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top