Question

We have a very data centric application, which is often run across networks with questionable connectivity.

We want to feedback to clients when the database is offline, and display some kind of warning screen - with error information - until the network comes back and the database is available again. I'd like to display the same screen whenever the database is unavailable for any reason - ie: service stopped, paused, login failure, network off, etc.

I have a routine handling SQLClient.SQLException, which I then parse for SQLErrors and check the numbers, problem is there are loads of different error numbers for failures and I keep missing some.

Is there some simple, consistent way i can check if the database server is offline or unavailable? How do others handle this without letting some unhandled exception slip through?

Cheers

Was it helpful?

Solution

you can easily catch only sql exceptions like this:

try
{
... your code
{
catch(SqlException sqlEx)
{
... display your error page
}
catch(Exception ex)
{
... general error handling
}

OTHER TIPS

I'd try to create SqlConnection object with connection string for server I need to check connectivity to, try to Open() this connection and check for exceptions here. Not sure that's the most efficient, though...

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