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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Retrieving exit code from scm.exe

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 1

How 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 int
declare @server sysname
declare @cmd nvarchar(500)

select @server = 'MYSQLSERVER'

select @cmd = 'osql -S '+@server+' -E -Q "select 1"'

-- Returns 0 if able to connect
exec @retcode = master.dbo.xp_cmdshell @cmd ,no_output

if @retcode = 0
begin
print 'Server '+@server + ' is available'
-- Insert success code here
end
else
begin
print 'Server '+@server + ' is not available'
-- Insert failure code here
end



CODO ERGO SUM
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -