Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
Worth noting that if you're just restoring a local dev database, it may be more straightforward to just drop the database and then restore it from backup. – Drew Noakes Aug 5 '12 at 0:03

You can't restore the database when it is your default database. Check your login, and see what is set as the default database. Try setting the default database to 'master' and retry the restore.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.