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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem restoring Database after Backup

Author  Topic 

pee2002
Starting Member

16 Posts

Posted - 2009-07-27 : 04:31:49
Hi there!

I made a backup of my database (MandoTECA) using the following code:

CREATE PROCEDURE [dbo].[CreateBackup]
@uri nvarchar(MAX)
AS
BACKUP DATABASE MandoTECA
--TO DISK = 'C:\Users\Pedro\Desktop\MandoTECA.Bak'
TO DISK = @uri
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Backup Completo da MandoTECA';


And used it a restore procedure to do the restore:

CREATE PROCEDURE [dbo].[RestoreBackup]
@uri nvarchar(MAX)
AS

RESTORE DATABASE MandoTECA
FROM DISK = @uri


The problem is that it gives me the following error:



Can you help me?

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-07-27 : 04:55:34
it means that your connected to that database, as the error is indicating there can be no connections on the database which you are trying to restore.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-27 : 05:00:04
CREATE PROCEDURE [dbo].[RestoreBackup]
@uri nvarchar(MAX)
AS

EXEC(' USE MASTER
RESTORE DATABASE MandoTECA
FROM DISK = '''+@uri+'''')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pee2002
Starting Member

16 Posts

Posted - 2009-07-27 : 05:00:23
Yes, i know that but when i call this SP in my application the Management Studio is closed so the is only one client in the DataBase.

:(
Go to Top of Page

pee2002
Starting Member

16 Posts

Posted - 2009-07-27 : 05:03:38
quote:
Originally posted by madhivanan

CREATE PROCEDURE [dbo].[RestoreBackup]
@uri nvarchar(MAX)
AS

EXEC(' USE MASTER
RESTORE DATABASE MandoTECA
FROM DISK = '''+@uri+'''')

Madhivanan

Failing to plan is Planning to fail



It gives me exactly the same error :((

And i closed the Managment Studio..
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-07-27 : 08:08:38
There cannot be anyone connected to the database when you go to restore it. Even the connection that's running the restore has to be using a different database.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-27 : 08:23:02
Run this to know who are all connected to Server

EXEC sp_who

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

saran_d28
Starting Member

36 Posts

Posted - 2009-07-28 : 03:07:55
Hi,

Create procedure (restore backup procedure) in master database, and connect the master database from your front end application. Then its work fine.

u can restore any database from master database only.
Go to Top of Page

pee2002
Starting Member

16 Posts

Posted - 2009-07-29 : 06:48:04
Its exactly that.

I created in the master Database and worked just fine.

In my application i have another connectionString to the Master Database just to call the restore Stored Procedure.

Thanks
Go to Top of Page
   

- Advertisement -