Re: Scripting in Windows 2000 Advanced Server
- From: zoeygirl <zoeygirl@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 1 Sep 2006 11:36:02 -0700
"Richard Mueller" wrote:
"zoeygirl" <zoeygirl@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4ECD5E62-4035-499C-920C-B4AD1D97A3FB@xxxxxxxxxxxxxxxx
I need to check to see if a service is running ie: "mssqlserver service",
if
it's not I then need to stop another service that is dependent on the
"mssqlserver service which is clustered". Consequently I will then need to
start both the above services on the second clustered sql server. I have
no
idea where to start in order to script these functions. Any assistance
would
be greatly appreciated.
Hi,
I use would use the "net start" and "net stop" commands. However, I haven't
used them in a script to determine if a service is running. I would use ADO
to attempt to connect to the master database in the default instance of SQL
Server, trapping the possible error. If the connect succeeds, mssqlserver is
running. If the connect fails (assuming a good connection string and
adequate permissions) I think the service is not running. Otherwise, you
would have to run "net start", pipe the results to text file, and parse for
mssqlserver, which seems like a lot of work in a script/program.
In a batch file, you can run "net start" and "net stop", but connecting to
the master database with ADO would require VBScript (or possibly osql in a
batch file). I use the Run method of the wshShell object in VBScript to run
"net start mssqlserver" and "net stop mssqlserver". Brief VBScript snippets:
======
Set objShell = CreateObject("Wscript.Shell")
strCommand = "%COMSPEC% /c net start MSSQLSERVER"
intReturn = objShell.Run(strCommand, 0, True)
If (intReturn <> 0) Then
' Cannot start SQL Server - ignore error.
' The SQL Server could already be running.
End If
======
' Connection string for SQL Server Master database
' in the default instance.
' Assumes Windows Integrated Authentication.
strServer = "MyServer"
strConnect = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=Master;" _
& "SERVER=" & strServer
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.ConnectionString = strConnect
On Error Resume Next
adoConnection.Open
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Unable to connect to the Master database."
Else
On Error GoTo 0
Wscript.Echo "Connected to Master database"
End If
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
Thanks Richard,
I was hoping for something a little less complicated, since I'm not familiar
with the SQL and connecting to the DB, maybe our resident sql guy can assist
me with your solution!
.
- References:
- Re: Scripting in Windows 2000 Advanced Server
- From: Richard Mueller
- Re: Scripting in Windows 2000 Advanced Server
- Prev by Date: Re: Scripting in Windows 2000 Advanced Server
- Next by Date: Re: Creating users from a text file
- Previous by thread: Re: Scripting in Windows 2000 Advanced Server
- Next by thread: Re: Scripting in Windows 2000 Advanced Server
- Index(es):
Relevant Pages
|
Loading