Re: Scripting in Windows 2000 Advanced Server





"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!
.



Relevant Pages

  • Re: Scripting in Windows 2000 Advanced Server
    ... "mssqlserver service which is clustered". ... used them in a script to determine if a service is running. ... to attempt to connect to the master database in the default instance of SQL ... ' Cannot start SQL Server - ignore error. ...
    (microsoft.public.windows.server.scripting)
  • Re: One Connection String for Multiple Users (SQL)
    ... Hitchhiker’s Guide to Visual Studio and SQL Server ... "William Vaughn" wrote: ... This uses the> same connection string for all instances of the application. ...
    (microsoft.public.sqlserver.connect)
  • RE: How do I configure Analysis Services for Excel 2003 users?
    ... they had had Office 2003 installed AFTER SQL Server. ... > I have been preparing a set of cubes in Analysis Services 2005 to be viewed ... > Excel reports have been designed as pivot tables based on AS cubes, ... > Surely it must be that the connection string is incorrect but I seem to have ...
    (microsoft.public.sqlserver.olap)
  • Re: Connecting to Sql Server using an IP address
    ... using IP address without port number (default port number ... of SQL Server is 1433) cannot connect to the SQL Server on a remote ... name in the connection string can connect the remote machine successfully. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem connecting to an SQL 2005 Express Instance in RANU mod
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... I'm using SQL2005 Express User Instance Feature. ... attaching an MDB file with the following connection string: ...
    (microsoft.public.sqlserver.connect)

Loading