Sql-server – Can’t restore SQL 2008 backup – error that the database is in use but it isn’t

sqlsql serverwindows-server-2008

I am trying to restore a SQL Server 2008 backup and am getting the following error:

RESTORE cannot process database because it is in use by this session.

ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: RESTORE cannot process database 'database_name' because it is in use by this session. It is recommended that the master database be used when performing this operation. (Microsoft.SqlServer.Smo)

Any idea what is wrong?

Best Answer

It's only related to being your default database, because this is the db context when you connect. This is not the actual issue.

All you have to do is put "use master" above the restore to change the database context.

It may be that one of your clients relies on there being a default database... so changing it may cause issues later on.