[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

MV

3/22/2007 4:40:00 PM

Hi, I have to restore daily databases that are still in use, I can drop
connection without problem but I'm searching a way to scripting this step,
is there a way to drop connection, restore db via TSQL Script ? Thanks


3 Answers

Tony Rogerson

3/22/2007 5:18:00 PM

0

If you are using 2005....

http://sqlblogcasts.com/blogs/tonyrogerson/archive/2007/02/11/prevent-users-from-reconnecting-in-sql-s...

Tony.

"MV" <MV@MV.MV> wrote in message
news:uKKsuCKbHHA.588@TK2MSFTNGP06.phx.gbl...
> Hi, I have to restore daily databases that are still in use, I can drop
> connection without problem but I'm searching a way to scripting this step,
> is there a way to drop connection, restore db via TSQL Script ? Thanks
>

Hugo Kornelis

3/22/2007 6:10:00 PM

0

On Thu, 22 Mar 2007 17:39:35 +0100, MV wrote:

>Hi, I have to restore daily databases that are still in use, I can drop
>connection without problem but I'm searching a way to scripting this step,
>is there a way to drop connection, restore db via TSQL Script ? Thanks
>

Hi MV,

ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hug...

Rick Toner

3/22/2007 7:05:00 PM

0

I use this and it works every time:

IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
N'DataBaseName')
begin
ALTER DATABASE [DataBaseName] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE [DataBaseName]
end
GO

RESTORE DATABASE DataBaseName
FROM DISK = 'C:\Directory\DataBaseName.bak'
WITH MOVE 'DataBaseName_Data' TO 'C:\Directory\\DataBaseName.mdf',
MOVE 'DataBaseName_Log' TO 'C:\Directory\\DataBaseName_log.ldf'
GO


--
Rick Toner


"MV" wrote:

> Hi, I have to restore daily databases that are still in use, I can drop
> connection without problem but I'm searching a way to scripting this step,
> is there a way to drop connection, restore db via TSQL Script ? Thanks
>
>
>