Thursday, February 15, 2007

SQL Server 2005 DB Restore

I found myself getting the following error

TITLE: Microsoft SQL Server Management Studio
------------------------------

Restore failed for Server 'MyServer'. (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: RESTORE cannot process database 'MYDB' 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.2047.00&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

So after some googleing I found this.

USE master
RESTORE DATABASE MYDB
FROM DISK = 'C:\Documents and Settings\username\Desktop\myBackUpFile.bak'

this sets the table to master, and runs the same querry the wizard would. (Although this is a deprecated function)

2 comments:

Todd Hensley said...
This comment has been removed by the author.
Todd Hensley said...

I was getting the same problem trying to restore a database using the SQL Server Mangement Studio. I was able to eliminate the error by changing the default database of the login I was using to "master".