February 25, 2009 at 5:56 am
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."
February 25, 2009 at 10:47 pm
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
February 26, 2009 at 8:19 am
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.
February 27, 2009 at 4:45 am
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."
February 27, 2009 at 8:44 am
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
March 1, 2009 at 10:55 pm
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."
March 3, 2009 at 1:17 pm
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
March 3, 2009 at 1:38 pm
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
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
March 3, 2009 at 2:30 pm
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" 😉
March 4, 2009 at 5:26 am
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."
March 4, 2009 at 9:34 am
we run HP servers and install all the client HP software as part of the install. they have a utility called process monitor where you add the exe files, restart snmp and it send an alert if sql or any service you want to monitor stops
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply