When using SQL Server Management Studio to restore a backed-up database that you’ve created from a database already being used in your current instance of SQL/SQLExpress, you may receive an error similar to the following:
Restore failed for server 'servername' (Microsoft.SqlServer.Expre<wbr>ss.Smo) Additional Information: System.Data.SqlClient.SqlE<wbr>rro: The file 'D:\SQL Data\MSSQL\DATA\database.m<wbr>df' cannot be overwritten. It is being used by database 'database'. (Microsoft.SqlServer.Express.Smo)
This is due to the fact that you are trying to restore a database (essentially create a new instance of the database itself) that is already being used by some other db in your configuration. If you have backed up database “TestDB”, and are now trying to restore this .bak file to a db named “TestDB2”, you will need to change the path that this restoration is going to.
Head over to the ‘Options’ tab in SSMS, and edit the “Restore As” file paths to fix this error message. What it’s trying to do is overwrite one of your in-use database files with this restoration file, which would result in some pretty funky issues if it were to let you do this. Check out the screen below for a quick view on what to change.