Error: Restore failed for Server 'ServerName\InstanceName'. System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use.
TITLE: Microsoft SQL Server Management Studio
------------------------------
Restore failed for Server 'ServerName\InstanceName'. (Microsoft.SqlServer.SmoExtended)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&LinkId=20476
Solution
Try running any of this command and then try to restore.
ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE MyDatabaseNameSET SINGLE_USER WITH ROLLBACK AFTER 30
ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH NO_WAIT
ALTER DATABASE MyDatabaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE;
Source of Information