Windows – Programmatically Copy Database like SQL Server 2008 Copy Database Wizard

command-line-interfacesql-server-2008sql-server-2008-r2windows

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#?

Best Answer

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.