Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to stop or suspend database access?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01311527
Message ID:
01311561
Vues:
23
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform