Simple way to identify the SQL Server service is running or not!

CREATE TABLE #Services(ServerName VARCHAR(255))

INSERT  #Services
EXEC  xp_cmdshell 'NET START'

IF  EXISTS (SELECT 1 FROM #Services WHERE ServerName LIKE '%SQL SERVER%')
   SELECT 'SQL Service is running' [Status]
ELSE
   SELECT 'SQL Service is not running' [Status]


DROP  TABLE #Services
GO

No comments:

Post a Comment