Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Scripts          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

Start, Stop, Pause and Query Windows SQL Server Services Remotely


By:   |   Last Updated: 2010-08-26   |   Comments (3)   |   Related Tips: More > Database Administration

Problem

Sometimes SQL Server services or any other Windows service does not start due to some issue after a server reboot. When you try to login to the server you find that you do not have remote login rights to that server or remote login is disabled for that server. Here is a solution to start the service remotely. This tip is also useful if you want to start a number of services in a particular order.

Solution

To control the services remotely, we can use either the services.msc GUI or the SC (Service Control) command to start, query, stop, create and delete any Windows service remotely. The SC command is very useful when remote login is disabled and we want to start the service.

Permissions

You can set permissions for individual services by using Security Templates or using Security Policy.


Using the GUI - Services.msc

The first option is to use the Services application to control the services on a remote server. Type services.msc in the run window or go to Control Panel -> Administrative Tools -> Services. When this app opens, click on the Action menu and click on "Connect to another computer...".

Sometimes SQL Server services or any other Windows service does not start due to some issue after a server reboot

Enter the remote computer name as shown below and it will load the services of the remote machine. Once you connect you can manage the services as your normally do.

The first option is to use the Services application to control the services on a remote server


Using Command Prompt

The other option is to use the command line tool SC.exe.

Basic Syntax for SC.exe

SC [\\server] [command] [service name] [Options]

To get a list of options you can run sc /? as shown below. The below image lists the commands you can use with SC.

The other option is to use the command line tool SC.exe.

Example 1 - Start the SQL Server Service

This command will start the SQL Server service on server "\\computer100".

sc \\computer100 START "mssqlserver"

This command will start the SQL Server service on server "\\computer100".

Example 2 - Stop the SQL Server Service

This command will stop the SQL Server service on server "\\computer100".

sc \\computer100 STOP "mssqlserver"

This command will stop the SQL Server service on server "\\computer100".

Next Steps
  • Use the other command options and check the output
  • Create a batch file to start the different services using the SC command
  • When running this make sure you have the correct permissions to start and stop the services otherwise you will get an "Access is denied" error message.
  • When running the SC command on Vista, Windows 7, Windows 2008, etc... you may need to open the CMD prompt with the "Run as administrator" option.
  • Read more about the SC command


Last Updated: 2010-08-26


get scripts

next tip button



About the author
MSSQLTips author Jugal Shah Jugal Shah has 8+ years of extensive SQL Server experience and has worked on SQL Server 2000, 2005, 2008 and 2008 R2.

View all my tips
Related Resources




Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



Tuesday, October 16, 2012 - 2:22:18 PM - Jeremy Kadlec Back To Top

Jugal,

Thank you for this tip.  This worked well for me.  One thing I had to do was actually create a delay between stopping and starting services in one environment.  To do so, I included this code in my batch file to create the delay:

ping 1.1.1.1 -n 1 -w 10000

Thank you,
Jeremy Kadlec


Wednesday, February 15, 2012 - 4:40:25 AM - sumi Back To Top
hi, while connecting remote machine using the above commend i'm getting OpenSCManger failed. Access denied. Thanks, Sumi

Wednesday, September 08, 2010 - 12:05:11 PM - Gennadiy Chornenkyy Back To Top
Very helpful - thanks!


Learn more about SQL Server tools