Error:TITLE: Microsoft SQL Server Management Studio
------------------------------
Restore failed for Server 'database_name'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.3042.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------
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)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.3042.00&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
SOLUTION:
You can't restore a DB through the SSMS interface if it's your default DB for your login! Change the login's default DB then restore.
More detailed description:
Well, there's the obvious problem that you can't restore a database you have an open connection to, but in this case the cause was less obvious. I canceled out of the restore database dialog in SSMS and check the activity monitor. There were a few open connections for the database, so I closed my connections and killed any idle connections from other users. I tried it again. Same error message.
It turns out the problem is that the database I have setup as my windows logon default DB is the same DB I was trying to restore. So when SSMS makes the connection in the background, it creates a connection to that database. I had to change the default DB in my security info, and then restore the database.
Definitely a perfect candidate for the theme of this blog: posting errors and solutions for stuff I couldn't find posted elsewhere on the net. This one's probably out there, but it's not easy to find via a search engine, so hopefully this helped.