SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server Services


SQL Server Services

Author
Message
free_mascot
free_mascot
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4879 Visits: 2248
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 Sad

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."
Adiga
Adiga
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3352 Visits: 21012
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
rlondon
rlondon
SSC Eights!
SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)

Group: General Forum Members
Points: 843 Visits: 1160
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.
Attachments
MonitorServicesScript.txt (130 views, 1.00 KB)
free_mascot
free_mascot
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4879 Visits: 2248
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."
John Mitchell-245523
John Mitchell-245523
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19269 Visits: 16228
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
free_mascot
free_mascot
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4879 Visits: 2248
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 Smile

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
2 Tim 3:16
2 Tim 3:16
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1397 Visits: 1547
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
Jeffrey Williams 3188
Jeffrey Williams 3188
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10301 Visits: 10004
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 opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

Perry Whittle
Perry Whittle
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28021 Visits: 17352
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" ;-)
free_mascot
free_mascot
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4879 Visits: 2248
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 Smile

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."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search