0

I am creating a batch program which will stop the services of SQL Server and copy .mdf and .ldf files to a specified location.

This is my batch file:

 net stop mssqlserver

 xcopy /s "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\test.mdf"  "D:\backup"

 xcopy /s "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\test_log.ldf"  "D:\backup"

 net start mssqlserver 

It is stopping SQL Server Agent, but not SQL Server itself, so it cannot copy the files.

Why is it not stopping the SQL Server service?

What do I need to do to stop the SQL Server service?

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
speedyraz
  • 335
  • 1
  • 5
  • 18
  • 2
    Is there any output from the batch? – dean Jan 14 '17 at 09:06
  • Related question is : [Stop SQL Server from running until needed](http://stackoverflow.com/q/17284228/4519059) ;). – shA.t Jan 14 '17 at 09:38
  • Do you get any (error) message(s) when running this `NET STOP` command separately, from the `cmd.exe` command line? – marc_s Jan 14 '17 at 10:22
  • Are you sure your `SQL Server` service `instance name` is `mssqlserver`? It may have been installed using `named instance`. Check the `InstalledInstances` value under the `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server` registry key, or run `sc query mssqlserver` to test if it is the real friendly name of the service. – elzooilogico Jan 14 '17 at 10:37
  • Read more here: http://www.sqlservercentral.com/blogs/dugi/2010/06/23/stop-n-start-sql-services-via-command-prompt/ –  Jan 15 '17 at 12:16
  • Thanks all for reply . I found solution from Microsoft Support site and did following steps :- 1. Pause MS SQL Server with net pause mssqlserver 2. Stop Sqlserver Agent with net stop sqlserveragent 3. Stop MS SQL Server with net Stop mssqlserver recommend always use this approach for properly stopping services of SQL Server .. – speedyraz Jan 16 '17 at 05:32

0 Answers0