Checking to see if SQL Service is running

  • Thread starter Thread starter TheNortonZ
  • Start date Start date
T

TheNortonZ

I have users who, as soon as they boot into XP, immediately try to run my
app without waiting for all of the services to start. My app uses MSDE.

Is there something I can do in code to check to see if the service is
running to prevent them from running the app and therefore seeing any kind
of errors?

Thanks.

Norton
 
TheNortonZ said:
Is there something I can do in code to check to see if the service is
running to prevent them from running the app and therefore seeing any kind
of errors?

Have a look at this.

using System.Data.SqlClient;

SqlConnection conn = new SqlConnection("connection string here");

try
{
conn.Open();
}
catch (SqlException ex)
{
if (ex.Number == 17)
{
// Server: Msg 17, Level 16, State 1
// SQL Server does not exist or access denied
}
if (ex.Number == 17142)
{
// Server: Msg 17142, Level 16, State 1
// SQL Server has been paused. No new connection will be allowed
}
if (ex.Number == 18456)
{
// Server: Msg 18456, Level 16, State 1
// Login failed for user 'sa'
}
}
finally
{
conn.Dispose();
}
 
Back
Top