Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to find out how to stop / start MS SQL services so that I can copy SQL database files. I know how to do this manually but I would like to do this from a script.

share|improve this question

Instead of copying the data files, what about taking a backup copy? That way you don't need to stop/start the SQL Server service and cause downtime, like this for example:

BACKUP DATABASE [databasename] 
TO DISK = 'D:\BackupFiles\Database.bak' 

the COPY_ONLY flag specifies that the backup is (surprise surprise) only a copy, thus not break the differential backup chain.

share|improve this answer
And since you're looking to do this via a script you should execute the above SQL using the "sqlcmd" command prompt tool – Joel Mansford Sep 3 '12 at 14:45

for stopping:


for starting:


But i surgest if you want to copy the database files.. (I think for backup purposed).. you might consider using a maintenance plan with a backup schema if you already use MS SQL SERVER. For sql express you need some custom scripts. When the backup of your database is finished, the output file is not locked and you can store that one on a place you like for example a backup device.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.