How to check if SQL Server is running via asp.net

W

wwwmike

Problem: When my provider shuts down the SQL Server IIS receives a few
error messages and then switches the site to 'SERVICE UNAVAILABLE'.

Before IIS kills itself it is friendly enough to send me an error
message.

****ERROR MESSAGE 1******
System.Data.SqlClient.SqlException: An error has occurred while
establishing a connection to the server. When connecting to SQL Server
2005, this failure may be caused by the fact that under the default
settings SQL Server does not allow remote connections.


This error message happens when the server is offline and my ASP.NET 2
code tries to open a connection

.....
myConnection.Open()
.....

The last error message I receive is

*****ERROR MESSAGE 2*****
System.InvalidOperationException: Timeout expired. The timeout period
elapsed prior to obtaining a connection from the pool. This may have
occurred because all pooled connections were in use and max pool size
was reached


I am not sure if the ERROR MESSAGE 2 really is about the connection
pool, since the sql server is already down. But this might trigger IIS
to set my service unavailable.



What can I do in my asp.net code to detectd if a SQL server is online?
 
G

Guest

There are two specfic exceptions are thrown when you try to connect to the
back end i.e this line of code:

conn.Open()

1. InvalidOperationException

2. SqlException

What can I do in my asp.net code to detectd if a SQL server is online?

to resolve it ....catch SqlException error

If the Number property contains the value 18487 or 18488, this indicates
that the specified password has expired or must be reset. Check for Number
property to identify the cause of the issue..

Raj
 
J

Juan T. Llibre

re:
System.Data.SqlClient.SqlException: An error has occurred while
establishing a connection to the server. When connecting to SQL Server
2005, this failure may be caused by the fact that under the default
settings SQL Server does not allow remote connections.

Networking protocols are disabled by default in SQL Server Express.

If someone simply installs Express and chooses all the defaults, SQL Server Express will only
be able to have connections originating on the local machine where SQL Server is installed.

You need to expressly enable networking protocols.

To fix that, follow the instructions outlined at :
http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277
or
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=271795&SiteID=1
 
G

Guest

Wrap your first SQL call in a try /catch /finally block and output a friendly
message from within the exception block.
Peter
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top