Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 need the ability to copy a database similar to what the Copy Database wizard accomplishes in SQL Server, but in a more automated (i.e. command line) fashion. I am writing a small application in C# that is making a copy of a web site (both files and database).

Is there a way to execute whatever the Copy Database wizard in SQL Server 2008 does in the command line / C#?

share|improve this question
up vote 2 down vote accepted

Your best be would be to backup and restore the database using the BACKUP DATABASE and RESTORE DATABASE commands. The Copy Database Wizard can throw errors and miss stuff.

share|improve this answer
This is indeed the steps that I ended up having to take in order to correctly perform a copy. Thanks. – Scott Sep 23 '10 at 12:08
And once you do the BACKUP/RESTORE, just pay attention to the possibility of orphaned users. An overview of why (and how to deal with them) is here: – Michael K Campbell Sep 24 '10 at 19:17

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.