8

I need to start and stop SQL Server from the command line. I am willing to write a small C# program if necessary, but I suspect that there's something (PowerShell, maybe?) that currently exists that does this gracefully.

Thank you.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
rp.
  • 17,483
  • 12
  • 63
  • 79

7 Answers7

20

net {start|stop} mssqlserver

P Daddy
  • 28,912
  • 9
  • 68
  • 92
5

net start/stop

http://technet.microsoft.com/en-us/library/cc736564.aspx

Brian Rudolph
  • 6,142
  • 2
  • 23
  • 19
4

Or, in PowerShell, Stop-Service, Start-Service, or Restart-Service. Note that all of this has to be done on a per-instance basis, just as with the other suggestions here.

Don Jones
  • 9,367
  • 8
  • 39
  • 49
2

http://msdn.microsoft.com/en-us/library/ms187463.aspx

John Sheehan
  • 77,456
  • 30
  • 160
  • 194
0

Here's an answer that actually contains a little bonus information...and more thoroughly answers the question. What if you have more than one instance of SQL server? Then you need to know the extended syntax of NET START. You can start services by Name, not just by service moniker (or whatever mssqlserver is an example of):

NET START "sql server (instancename)"

This applies to other services, too. Want to start the System Event Notification Service?

NET START "System Event Notification Service"

Boom goes the dynamite! hehe

Newclique
  • 494
  • 3
  • 15
0

For restarting SQL Server and SQL Server Agent you can create a batch file called restartsql.bat with the following commands in it, save it, and run it when needed:

@ECHO OFF net stop "SQL Server Agent (MSSQLSERVER)" net stop MSSQLSERVER net start MSSQLSERVER net start "SQL Server Agent (MSSQLSERVER)"

Enjoy!

0

With the commands below, I could start and stop SQL Server 2019 Express:

net start "SQL Server (SQLEXPRESS)"
net stop "SQL Server (SQLEXPRESS)"

You can find the actual name of SQL Server on SQL Server Configuration Manager as shown below:

enter image description here

And, this is How to find and open SQL Server Configuration Manager.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129