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.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Is it possible to restore a database remotely?

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

Posted - 2011-10-04 : 15:29:34
well no..that's not it...I administer a bunch of databases remotely

Are you using a sql script or just the Studio?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-04 : 15:30:04
Wait..you're trying to restore master?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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'
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-04 : 15:54:20
[code]
USE [dba]
GO

SELECT @@SERVERNAME

-- ***
-- *** Make Sure the Server Name is
-- ***


-- Find the Database file to Restore. Make sure it's on the Server
EXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'


-- Look at the internal file information
RESTORE FILELISTONLY
FROM DISK = N'\\servername\instance\path\database.BAK'
GO

-- If the DB Exists, Kick everyone out

ALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence
-- Get the Logical file names from filelistonly

RESTORE 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'
, REPLACE
GO

ALTER DATABASE [database] SET READ_WRITE
ALTER DATABASE [database] SET MULTI_USER
GO
[/code]


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -