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:
01311543
Views:
26
>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
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform