Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to start & Stop all SQL services in one go

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2010-08-10 : 07:02:21
Hi All,

Do we have any command which start and Stop all SQL related services in one go ?

Thanks,
Gangadhar

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-08-10 : 08:54:51
What do you mean by "in one go"? Does it have to happen at the same time or can it be in sequence? If in sequence is good enough you can write a simple bat-script to do it for you I guess.

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

ramforlak
Starting Member

2 Posts

Posted - 2010-08-10 : 09:33:03
You can start by using dynamic services ..You can find this in services.msc...
check it

Ramachandra
Go to Top of Page

SQLvariant
Starting Member

5 Posts

Posted - 2010-08-11 : 11:53:44
You can certainly do this with PowerShell.

To stop all of the SQL Services on a machine you would just do:
Get-Service *SQL* | Stop-Service -Force


Now if you wanted to restart all of your SQL Services but didn't want to start any SQL Serveices that were currently stopped you would just run:
Get-service *SQL* | where-object {$_.Status -eq "Running"} | Restart-Service -Force


And I'm pretty sure that you're going to have to run both of those commands from an elevated shell (meaning that you'll have to right-click on PowerShell and select "Run as Administrator").

Aaron Nelson - @SQLvariant
http://sqlvariant.com/wordpress/
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-08-12 : 03:06:50
Ah...gotta love powershell! Too bad I haven't had much time working with it

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-12 : 04:16:25
Isn't that liable to start them in an order that is not parent-then-child?

FWIW we have a Batch file that stops all the services, in desired order (SQL Agent before SQL Service) and then restarts them (in the reverse order). I have a shortcut to that batch file on the desktop ...
Go to Top of Page

SQLvariant
Starting Member

5 Posts

Posted - 2010-08-12 : 08:11:17
quote:
Originally posted by Kristen

Isn't that liable to start them in an order that is not parent-then-child?


I was worried about that very same problem so I tested it on my local machine using the -Force parameter and all of my services came back up just fine. If you run into a problem with it let me know and I will figure out how to force the dependencies in order too.

But again, as my developers always say 'it worked fine on my machine'


Aaron Nelson - @SQLvariant
http://sqlvariant.com/wordpress/
Go to Top of Page

SQLvariant
Starting Member

5 Posts

Posted - 2010-08-12 : 13:21:58
quote:
Originally posted by Kristen

Isn't that liable to start them in an order that is not parent-then-child?


I tested it out one more time to verify. Turns out that if you run it without the -Force it won't even let you stop the service and gives you this error message:
Restart-Service : Cannot stop service 'SQL Server (KILIMANJARO) (MSSQL$KILIMANJARO)' because it has dependent
services. It can only be stopped if the Force flag is set.


But when you run it with the -Force it restarts them with the dependency order factored in and gives you this meaage:
WARNING: Waiting for service 'SQL Server (KILIMANJARO) (MSSQL$KILIMANJARO)' to finish stopping...
that finally goes away when the dependent services are able to start.

Aaron Nelson - @SQLvariant
http://sqlvariant.com/wordpress/
Go to Top of Page
   

- Advertisement -