This is a dumping ground of software development topics that I've run across and found interesting (mainly .NET development). Many topics are covered more thoroughly in other places, and much of the information is gleaned from other places, and I'll try to credit those sources when possible.

Friday, March 18, 2011

SQL Server: Restore cannot process database because it is in use by this session.

I tried to restore a SQL Server 2005 database, but kept getting the following error:

Restore cannot process database 'WTF' because it is in use by this session. It is recommended that the master database be used when performing this operation.

I opened Activity Monitor and killed a couple processes hanging on the database, but got the same error. When I opened the Activity Monitor again, one process had come back. I closed SSMS trying to get rid of this process, to no avail. I googled a bit and found various people going round and round about it, then found this simple solution from The DW Experience.

The problem was that my SQL login had its "Default database" set to the database I was attempting to restore, which keeps opening a session. By changing the default database to something else, I could finally restore the database. Then I promptly set the default database back, because that's the way I like it. Since I'll probably run into this problem again, I figured I should write it up here.

3 comments:

Unknown said...

Restore SQL database with simplicity and comfortably with the help of SQL repair tool. Try and read about it from here :- http://www.sqlrepairtool.org

Unknown said...

Use Sql Database Recovery that can repair and restore MDF file with its element tables, triggers, views, store procedure, XML data types & user define data without facing any problem. The software recovers SQL Server 2012, 2008 / 2008 R2, 2005 and 2000 database files.

Visit Link:-
http://www.recoverydeletedfiles.com/sql-database-recovery-software.html

Anonymous said...

SQL Server Recovery tool to recover data from corrupt and damaged SQL database files, you need to check out the SQL Recovery software’s feature and functionalities by downloading it.

More info :- http://www.mannatsoftware.com/stellar-phoenix-sql-server-recovery.html

Followers