How to start and stop the SQL Server service from command line

Here are a couple ways to stop and start the SQL Server service from a command line:

Option 1: use the NET START and NET STOP commands:

NET START MSSQLSERVER

and

NET STOP MSSQLSERVER

If you have a named instance, you will have to replace the ‘MSSQLSERVER’ with the proper service name, for example MSSQL$SQL2008 .

!!! Keep in mind that you need to have the proper permissions to execute the command. You either need to be a system administrator, or you need to run the CMD as an administrator.

 

Option 2:

Use a VB script like this to start the service:

'Start Service
strServiceName = "MSSQLSERVER"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name like '" & strServiceName & "'")
For Each objService in colListOfServices
 objService.StartService()
Next

and a script like this to stop the service:

'Stop Service
strServiceName = "MSSQLSERVER"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name like '" & strServiceName & "'")
For Each objService in colListOfServices
 objService.StopService()
Next

Why would this be useful? Because even though you may not want to stop the services on a production system, you might want to do so on a home testing system if you do not need the services at the moment and you would like to free some resources to the system.

 

 

Comments are closed.