Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ravl13
Starting Member
38 Posts |
Posted - 2011-10-04 : 15:25:25
|
Hi again,So I'm using Management Studio at my workstation, and I'm trying to restore a database (bnbcontacts) on another computer. I have a connection to the target machine in Management Studio, and use the Restore Database wizard. When I click OK however, I get this message:TITLE: Microsoft SQL Server Management Studio------------------------------Restore failed for Server 'SQLSERVER01\HOTTSQLSERVER08'. (Microsoft.SqlServer.SmoExtended)------------------------------ADDITIONAL INFORMATION:System.Data.SqlClient.SqlError: RESTORE cannot process database 'bnbContacts' because it is in use by this session. It is recommended that the master database be used when performing this operation. (Microsoft.SqlServer.Smo)------------------------------BUTTONS:OK------------------------------I don't have any query windows open, so that's not causing the problem. What the message sounds like to me is that I can't restore because I am using a computer that the database isn't on.I have tried right-clicking on the master database, and doing a restore database... from there, since that's what the message seems to imply the correct thing to do is, but even though I specify bnbcontacts in the to Database and From Database fields, I still get the same error message. This leads me to believe that you can't remotely do database restores. Is this a correct assumption? |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
ravl13
Starting Member
38 Posts |
Posted - 2011-10-04 : 15:35:12
|
I'm just using the studio's wizard. I don't know how to do restore queries.I'm not trying to restore the Master database. But the message made it sound like it was involved somehow. I'm trying to restore a normal, non-system database named 'bnbcontacts' |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2011-10-04 : 15:54:20
|
[code]USE [dba]GOSELECT @@SERVERNAME-- ***-- *** Make Sure the Server Name is -- ***-- Find the Database file to Restore. Make sure it's on the ServerEXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'-- Look at the internal file informationRESTORE FILELISTONLY FROM DISK = N'\\servername\instance\path\database.BAK' GO-- If the DB Exists, Kick everyone outALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATEGO-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence-- Get the Logical file names from filelistonlyRESTORE DATABASE [database]FROM DISK = N'\\servername\instance\path\database.BAK' WITH MOVE 'logical data file' TO '\\servername\instance\datafilepath\database.MDF' ,MOVE 'logical log file' TO '\\servername\instance\datafilepath\database_log.LDF' , REPLACEGOALTER DATABASE [database] SET READ_WRITEALTER DATABASE [database] SET MULTI_USERGO[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
|
|
ravl13
Starting Member
38 Posts |
Posted - 2011-10-04 : 16:11:29
|
So, after some digging around on posts with the same error message, I found out the error was happening because bnbcontacts was my default database. I set my default to another database, and the backup worked fine.Then I switched the default back to bnbcontacts. |
|
|
|
|
|
|
|