I have two SQL Server connection strings, CX and CY.
What I need to do is
- Ensure CY has no tables in it.
- Backup the database CX.
- Restore it to CY.
Haven't found what I am looking for yet. I don't want a tool to do this, I need to do it in C# code at runtime because the action of adding a new Client needs to copy a master DB to an empty DB. I can't use a pre-made script because I need to also copy data, and the master DB could have been updated only seconds before the new client was added.
===UPDATE===
I am using Smo.Backup and Smo.Restore. When I try to restore I get:
ERROR 3154 The backup set holds a backup of a database other than the existing database.
Can anyone tell me how to get around this? Other than that I have a working solution!
Thanks
Pete