Few days back, I created a testing environment(test1_MSCRM) for one of my Live-Organisation through Import Organization in the deployment Manager. For some further RnD purpose, I wanted to create yet another test organization (test2_MSCRM) for the same Live-Organization on the same server where I already had previous test1_MSCRM.
So, I created a new DB(test2_MSCRM) on my SQL-Sever and tried to restore the full backup of my Live organization, same way as I did while creating test1_MSCRM. But this time the Restore failed with the following Error:
Restore failed for server.(Microsoft.SqlServer.SmoExtended). System.Data.SqlClient.SqlError: The file 'C:\ProgramFiles\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1_MSCRM.mdf' cannot be overwritten. It is being used by database 'test1_MSCRM'. (Microsoft.SqlServer.Smo)
Error clearly mentioned that my backup (test1_MSCRM.mdf) was trying to restore my previous test1_MSCRM.mdf file which is already being used by the test1_MSCRM database.
Actually While restoring I created the new DB with different name but forgot to change the file name for .mdf and .ldf which was taken while Backup.
To change the file name:
- Click on Options.
- At right side, Under ‘Restore the database file as:‘ section. The first column represent the original file names of file type .mdf and .ldf and right most column represents the file name which you want to provide and restore the DB file as.
- Click on the browse button and scroll all the way to see the file name and change it to your preferred name(test2_MSCRM.mdf and test2_MSCRM.ldf).
After changing the restore database file name as, my DB restore succeeded.
Hope this was Helpful.