Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to stop or suspend database access?
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01311527
Message ID:
01311561
Views:
22
>>Hello everybody,
>>
>>I backup my drive (where SQL Server database reside) by copying the entire drive to an external drive. But when I do it, I get message that the sql database file failed to be copied (not exactly these words but something like this). Of course, this is because SQL Server has connection to the database.
>>
>>Is it possible to temporarily suspend SQL Server connections to the databases? How do you do it?
>>
>>Thank you.
>
>NOT TESTED AT ALL (I don't know how to mark this more :o)))
>
>--- Kill all established connections to that DB
>DECLARE @Test TABLE (spid smallint, ecid smallint, status nchar(30), loginame nchar(128), hostname nchar(128), blk char(5), dbname nchar(128), cmd nchar(16),  request_id int)
>INSERT INTO @Test
>EXEC sp_who
>SELECT * FROM @Test
>DECLARE @spid smallint
>DECLARE @sql varchar(200)
>SELECT @spid = MIN(SpId) FROM @Test WHERE dbname = 'YourDataBaseNameHere'
>
>WHILE @spid IS NOT NULL
>      BEGIN
>         SET @sql = 'KILL '+CAST(@spid as varchar(50))
>         EXEC (@sql)
>         SELECT @spid = MIN(SpId) FROM @Test WHERE dbname = 'YourDataBaseNameHere' AND SpId > @spid
>      END
>
>ALTER DATABASE Test SET SINGLE_USER
>BackUp-----
>
>ALTER DATABASE Test SET MULTI_USER
>
Thank you, Borislav.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform