|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
Good Day,
I am looking for small .bat code to find the status of SQL Server windows services.
In fact I have tried to find it on google but no luck 
Appreciate if anybody can help with this.
Thanks in advance.
Cheers!!!
--------------------------------------------------- "Thare are only 10 types of people in the world: Those who understand binary, and those who don't."
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:50 AM
Points: 1,618,
Visits: 20,898
|
|
There is useful command line utility called "SC". With this you can query the service status as below.
SC query mssqlserver
Hope this helps.
Cheers,
Pradeep
Pradeep Adiga Blog: sqldbadiaries.com Twitter: @pradeepadiga
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Friday, May 03, 2013 12:41 PM
Points: 417,
Visits: 1,122
|
|
I have uploaded an attachment of a .vbs file (I changed the extension to .txt for uploading) that I put together to monitor windows services every few minutes and e-mail me with any changes. I would run this through a scheduled task and it worked great. The only problem was that if the server was restarted for any reason, the job would not run and I would have to start it manually. The script may be useful for you anyway. If anyone can figure out why it won't restart automatically let me know.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
Thank you Adiga & rlondon.
Yes both of your reply will be useful.
--------------------------------------------------- "Thare are only 10 types of people in the world: Those who understand binary, and those who don't."
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 4,422,
Visits: 7,179
|
|
Here's a way of doing it in T-SQL. Obviously it won't work if the SQL Server service itself isn't running!
EXEC master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLAgent' John
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
Thank you, John.
Your query works but in case if SQL server is down we won't be able to track it.
So any solutions are welcome; when SQL server stops :)
--------------------------------------------------- "Thare are only 10 types of people in the world: Those who understand binary, and those who don't."
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:45 AM
Points: 1,081,
Visits: 1,453
|
|
You can create a scheduled job in another sql server on another box. Create a link and then run a simple query like "select count(*) from linkname..sys.sysdatabases;". You can schedule the job to run every minute and if the job fails, notify you by email.
Tim White
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Friday, May 17, 2013 11:21 AM
Points: 4,317,
Visits: 9,216
|
|
Using Powershell installed on any system that has network access:
PS> Get-WMIObject Win32_Service -computer {computer} | ? {$_.Name -like 'MSSQL*'} | Select Name, State
You can then extend this to send email what the state is not running, or you can issue a start, or anything else.
Jeffrey Williams Problems are opportunites brilliantly disguised as insurmountable obstacles.
How to post questions to get better answers faster Managing Transaction Logs
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 5,201,
Visits: 11,152
|
|
you could use VBS something along the lines of
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_Service where displayname like '%sql%'",,48) For Each objItem in colItems Wscript.Echo "-----------------------------------" Wscript.Echo "Win32_Service instance" Wscript.Echo "-----------------------------------" Wscript.Echo "DisplayName: " & objItem.DisplayName Wscript.Echo "Name: " & objItem.Name Wscript.Echo "ProcessId: " & objItem.ProcessId Wscript.Echo "Status: " & objItem.Status Next
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
Hello '2 Tim 3:16',
Nice solution We can cerate the link server and surely it works but what if customer do not agree for link server?
Also due to some security issues some of the client do not allow linked server :)
Thank you Jeffrey & Perry for your inputs.
Cheers!!!
--------------------------------------------------- "Thare are only 10 types of people in the world: Those who understand binary, and those who don't."
|
|
|
|