Search code examples
c#.netsql-server-2005.net-3.5smo

Restore database from .bak file with new name


I am sing C#, .NET 3.5, and SMO to create a copy of a database (our production database) to some other databases (our DEV and Test-database) in SQL Server 2005.

I have managed to create a backup from a database, an to restore it. this of course overwrites the existing one. I have used this CodeProject guide.

How do I restore a backup of a database into another database, with a different name on the same server?


Solution

  • In short:

    1. set the Restore.Database property to a new name,
    2. set the Restore.ReplaceDatabase property to true,
    3. specify new data and log files using the Restore.RelocateFiles property.