How to tell if SQLServer is running? 
Author Message
 How to tell if SQLServer is running?

I have a series of programs (written in VB6, of course) that interact
with a couple of SQLServer databases. I have each of the programs
check, upon startup, to see if SQLServer is up and running. I'm doing
this by "connecting" to one of the databases. But this requires that
the user actually "logs in" to the database.

I would like to do this check without requiring a log in. All I want
to do is verify that the SQL service is up and running and I can bring
up an appropriate error message if necessary. When the user eventually
gets to the point in the program where he needs to access some data
then I'll make him log in.

Any suggestions?

Thanks.



Wed, 01 Feb 2012 00:14:54 GMT  
 How to tell if SQLServer is running?

Quote:
> I have a series of programs (written in VB6, of course) that interact
> with a couple of SQLServer databases. I have each of the programs
> check, upon startup, to see if SQLServer is up and running. I'm doing
> this by "connecting" to one of the databases. But this requires that
> the user actually "logs in" to the database.

> I would like to do this check without requiring a log in. All I want
> to do is verify that the SQL service is up and running and I can bring
> up an appropriate error message if necessary. When the user eventually
> gets to the point in the program where he needs to access some data
> then I'll make him log in.

> Any suggestions?

Hmmm... been a while, and I can't find the code anymore - but, there is a way
using the api to check the status of a service.  I believe the calls were
OpenSCManager, OpenService, and QueryServiceStatus or maybe
QueryServiceStatusEx....  Anyway, maybe that will get you started anyway :)

--
Tom Shelton



Wed, 01 Feb 2012 00:47:08 GMT  
 How to tell if SQLServer is running?


Quote:
>I have a series of programs (written in VB6, of course) that interact
> with a couple of SQLServer databases. I have each of the programs
> check, upon startup, to see if SQLServer is up and running. I'm doing
> this by "connecting" to one of the databases. But this requires that
> the user actually "logs in" to the database.

> I would like to do this check without requiring a log in. All I want
> to do is verify that the SQL service is up and running and I can bring
> up an appropriate error message if necessary. When the user eventually
> gets to the point in the program where he needs to access some data
> then I'll make him log in.

If you try to connect with a bad user/password pair doesn't the error you
get back tell you that the server is running?


Wed, 01 Feb 2012 00:55:21 GMT  
 How to tell if SQLServer is running?


Quote:
> I have a series of programs (written in VB6, of course) that interact
> with a couple of SQLServer databases. I have each of the programs
> check, upon startup, to see if SQLServer is up and running. I'm doing
> this by "connecting" to one of the databases. But this requires that
> the user actually "logs in" to the database.

> I would like to do this check without requiring a log in. All I want
> to do is verify that the SQL service is up and running and I can bring
> up an appropriate error message if necessary. When the user eventually
> gets to the point in the program where he needs to access some data
> then I'll make him log in.

> Any suggestions?

> Thanks.

Here is something I stole from someone around here ..

Function IsServiceRunning(sServiceName)
    Dim objInst, objSet
    IsServiceRunning=FALSE
    Set objSet = GetObject("winmgmts:").ExecQuery("SELECT * FROM
Win32_Service")
    For each objInst IN objSet
        If (UCase(sServiceName) = UCase(objInst.Name)) And
(UCase(objInst.State) = UCase("Running")) then
            IsServiceRunning=TRUE
        End if
    Next
End Function

you can modify to fit

Also you can use the Service Controller directly
"How To Call EnumServicesStatus API From Visual Basic"
http://support.microsoft.com/kb/183478

There was discussion on this just a few days ago. Scroll down to
"Running a Windows command from VB"

But frankly, I've played with this in the past, and when is all said and
done, because of the various ways Admins set up security/permissions, etc.
I've found that letting the user login and then catching the error the
simplest and most reasonable solution. But of course I know squat about YOUR
domain problem. <grin>

-ralph

.



Wed, 01 Feb 2012 00:58:04 GMT  
 How to tell if SQLServer is running?


Quote:



>>I have a series of programs (written in VB6, of course) that interact
>> with a couple of SQLServer databases. I have each of the programs
>> check, upon startup, to see if SQLServer is up and running. I'm doing
>> this by "connecting" to one of the databases. But this requires that
>> the user actually "logs in" to the database.

>> I would like to do this check without requiring a log in. All I want
>> to do is verify that the SQL service is up and running and I can bring
>> up an appropriate error message if necessary. When the user eventually
>> gets to the point in the program where he needs to access some data
>> then I'll make him log in.

>If you try to connect with a bad user/password pair doesn't the error you
>get back tell you that the server is running?

Yes - At your suggestion I tried this and it does just what I want.
All I had to do was check for the appropriate error number.

Thanks.

why didn't I think of that?  :)



Wed, 01 Feb 2012 01:56:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to tell if MS SQLServer is installed on a machine

2. Calculations and validations inside Datagrid(i am using sqlServer database)

3. Please tell me what I am doing wrong - DAO parameter Append Query :(

4. How can I tell if I am connected to the network

5. Will somebody tell me what I am doing wrong with this ListView Control

6. tell another program i am done

7. How to tell if I am connected with PPP

8. How to tell which directory the access database is running in

9. How to tell if MAPI is running

10. GetObject() not telling me when the COM application is already running

11. Tell system not to run macro?

12. Tell system not to run macro

 

 
Powered by phpBB® Forum Software