SQL Server Services

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

  • 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

  • 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.

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

  • 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

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

  • 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

  • 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

  • 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" 😉

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

  • 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