Tips ‘N’ Tricks – Windows – Starting, Stopping, and Restarting Services from Command Line

Most of the Softwares/Applications that we install on Windows, run as (have an associated) Windows Service(s) which are long running executables which run in their own sessions and do not require user intervention. These services can be Started, Stopped, or Restarted on a need by need basis depending upon whether you are running the application or not (whether you need to use that application or not).

Like any other software, there are many Windows Services associated with SQL Server, depending upon the components that are installed like Database Engine, Integration Services, Analysis Services, and Reporting Services etc. And since these services are long running executables which run on their own in the background, they use some amount of system resources even when you are not using the corresponding application/piece of software, as a result the system performance might get impacted. Also sometimes you might need to turn off some service which is not required, you may need to restart some service for certain changes to take effect and so on. To address this, often we follow the below listed steps to Start/Stop/Restart a Windows Service:

  • Go to Control Panel | Administrative Tools | Services (or Alternatively type services.msc in Run command and hit enter).
  • Right-Click on a Service and select from the available options: Start, Stop, Pause, Resume, and Restart

This is the usual approach and works just fine. But some people are more comfortable doing things pretty much from Command Prompt. Windows provides a set of commands to address this very need of controlling the services from Command Prompt.

To Stop a Service: Type NET STOP “SQL Server (MSSQLSERVER2K8R2)”

To Start a Service: Type NET START “SQL Server (MSSQLSERVER2K8R2)”

To Restart a Service, you can run the above two commands one after the other.

Similarly there are commands like NET PAUSE, NET CONTINUE etc. For more information, visit this msdn article.

To simplify this further, I have created batch files to Start, Stop, and Restart each of the Windows Services associated with SQL Server. My list of batch files looks something as shown below:

To make best use of the available system resources, I always turn off the Windows Services which I don’t need like if I am working on an ETL project, the probability of me using Reporting Services or Analysis Services will be very minimal and on a need by need basis, hence I turn them off πŸ™‚

Note: The above steps are based on a Named Instance of SQL Server installed on Windows XP. The steps should be pretty much same for any version of SQL Server or any Windows Service in general.

Take a look at the other Tips and Tricks in this Series on Tips, Tricks, Techniques, and Shortcuts to Improve Productivity, and Design and Coding Skills.

Advertisements

About Dattatrey Sindol (Datta)

Datta is a Microsoft BI Enthusiast, passionate developer, and a blogger. View Full Profile

Posted on June 6, 2012, in Shortcuts, SQL Server, SSAS, SSAS Tips, SSIS, SSIS Tips, SSRS, SSRS Tips, Tips 'N' Tricks, Windows, Windows Tips and tagged , , , , , , , , , , , , , , , . Bookmark the permalink. 2 Comments.

What are your thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: