Home All Groups Group Topic Archive Search About

Checking to see if SQL Service is running

Author
3 Jan 2005 6:18 PM
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
Author
3 Jan 2005 6:25 PM
Sahil Malik
Norton,

Yes you can !!

You'd use System.ServiceProcess.ServiceController to check the
ServiceControllerStatus Enumeration to check and see if MSDE is running or
not.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Show quoteHide quote
"TheNortonZ" <thenort***@hotmail.com> wrote in message
news:#XCJYCc8EHA.2700@TK2MSFTNGP14.phx.gbl...
> 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
>
>
Are all your drivers up to date? click for free checkup

Author
3 Jan 2005 8:24 PM
Sahil Malik
BTW, you can also do this using WMI .. Select * from Win32_Service.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

Show quoteHide quote
"TheNortonZ" <thenort***@hotmail.com> wrote in message
news:#XCJYCc8EHA.2700@TK2MSFTNGP14.phx.gbl...
> 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
>
>
Author
8 Jan 2005 10:23 AM
Fabio
TheNortonZ wrote:
> 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();
}


--
Software is like sex: it's better when it's free -- [Linus Torvalds]

Fabio Marini - A+, RHCT, MCDBA, MCAD.NET
To reply: news [at] mamakin1976 [dot] plus [dot] com

Bookmark and Share