Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rizlaa
Starting Member
2 Posts |
Posted - 2006-03-10 : 09:52:37
|
Hi,I would like to know if it is possible to retrieve the exit code from scm.exe.I am trying to use the command line to detect if a SQL Server is running or not.I am executing the following (from the command line):scm -Action 3 -service MSSQLServer -Silent 1How do you get the exit code???Regards,Riz |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-03-10 : 11:13:09
|
Thic code will tell you if a SQL Server is running.declare @retcode intdeclare @server sysnamedeclare @cmd nvarchar(500)select @server = 'MYSQLSERVER'select @cmd = 'osql -S '+@server+' -E -Q "select 1"'-- Returns 0 if able to connectexec @retcode = master.dbo.xp_cmdshell @cmd ,no_outputif @retcode = 0 begin print 'Server '+@server + ' is available' -- Insert success code here endelse begin print 'Server '+@server + ' is not available' -- Insert failure code here end CODO ERGO SUM |
 |
|
rizlaa
Starting Member
2 Posts |
Posted - 2006-03-10 : 13:04:34
|
Thanks for the reply.I was wondering if this was the best command line tool to use for testing whether a MS SQL Server was running or not?Are there any other tools?Regards,Riz |
 |
|
|
|
|