SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deattach or take offline the DB to copy


Deattach or take offline the DB to copy

Author
Message
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3261 Visits: 3668
viji (7/26/2009)
thanks,

is there any other command just to close all the connections??

regards
viji

The command i wrote would be sufficient. the other way is to terminate all open connections using KILL.



Pradeep Singh
Anamika
Anamika
Mr or Mrs. 500
Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)

Group: General Forum Members
Points: 594 Visits: 1026
sorry,
let me be more clear
i want to close all the connections but not to take the db offline.

is there a command to do all this by one shot becoz KILL have to issue many times to kill all the processes........?

thanks
regards
viji
Gingkoo
Gingkoo
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 202
ALTER DATABASE YourDB SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Or this will do the job. Sorry about the cursor, an old script but you get the idea. sp_ on master will make available to all dbs, bad practice, not that you seem to mind Smile..

USE [master]
go

CREATE PROCEDURE sp_killprocess

@dbname varchar(128)

AS

SET NOCOUNT ON
SET QUOTED_IDENTIFIER OFF

declare @kill_id int
declare @query varchar(320)

declare killprocess_cursor cursor for

select a.spid from sysprocesses a join
sysdatabases b on a.dbid=b.dbid where b.name=@dbname

open killprocess_cursor

fetch next from killprocess_cursor into @kill_id

while(@@fetch_status =0)
begin
set @query = 'kill '+ convert(varchar,@kill_id)
exec (@query)
fetch next from killprocess_cursor into @kill_id
end

close killprocess_cursor
deallocate killprocess_cursor


GO
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3261 Visits: 3668
viji (7/27/2009)
i want to close all the connections but not to take the db offline.

The first two lines from the post of Victor are other two methods on how to disconnect all connections while your db will be still online. Single_user puts the database in single usesr mode(only one user can connect at a time).
If u're putting the database in restricted_users, only members of sysadmin would be able to connect to the database.



Pradeep Singh
tushaar.kudalkar
tushaar.kudalkar
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 Visits: 44
Hi

U need to stop the server services or else u will not be able to move ur .mdf and .ldf files
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3261 Visits: 3668
tushaar.kudalkar (7/27/2009)
Hi

U need to stop the server services or else u will not be able to move ur .mdf and .ldf files

Do we really need to stop the services? i guess once u detach a db, the mdf and ldfs will not be in use by sql server and hence u can move the files without restarting the services.



Pradeep Singh
Anamika
Anamika
Mr or Mrs. 500
Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)Mr or Mrs. 500 (594 reputation)

Group: General Forum Members
Points: 594 Visits: 1026
Thanks,
the suggestions helped me a lot.

regards
viji
Ice007
Ice007
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 22
VIJI,
I am new to SQL but i am going to try your advice.

1) how stop all current transaction to that DB (let my db name be Analytic)

2) after taking it offline Just copying the Analytic.mdf and analytic.ldf to network location with click of your mouse will work? ( because I tried it doing it w/o taking it offline and gave me error: other users might be using it please stop the process and try again)


3) if yes , then I can delete current mdf and ldf file and just create a new one with same names ?

4) then bring it online and everything should work normal , Any idea of it not working when taking it online?
except the fact I lose current data in production

Please advice.

Best
Ash
Michael L John
Michael L John
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2950 Visits: 7799
tushaar.kudalkar (7/27/2009)
Hi

U need to stop the server services or else u will not be able to move ur .mdf and .ldf files


This is not true. The only time you would need to do ths is if there are jobs that will access this database. And, if that is true, you will only need to stop and disable the affected jobs. Stopping the service is overkill.

Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87927 Visits: 45274
Please note: 4 year old thread.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search