dbTalk Databases Forums  

Disconnect all users

microsoft.public.sqlserver.setup microsoft.public.sqlserver.setup


Discuss Disconnect all users in the microsoft.public.sqlserver.setup forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
James
 
Posts: n/a

Default Disconnect all users - 05-20-2004 , 09:10 AM






I'm resoring my sql database on a nightly basis, but sometimes it fails as
some users leave there connection to the database up.
Could someone give me the script, or point me in the right direction for a
script that will disconnect all open sessions.

Thanks a lot



Reply With Quote
  #2  
Old   
Dejan Sarka
 
Posts: n/a

Default Re: Disconnect all users - 05-20-2004 , 09:57 AM






You can use Alter Database to put the database into single user mode and
use the with rollback immediate clause. There is a sp to kill all users at
http://www.dbmaint.com/download/util...kill_users.sql.

--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com

"James" <Homer@jamco> wrote

Quote:
I'm resoring my sql database on a nightly basis, but sometimes it fails as
some users leave there connection to the database up.
Could someone give me the script, or point me in the right direction for a
script that will disconnect all open sessions.

Thanks a lot





Reply With Quote
  #3  
Old   
Hari Prasad
 
Posts: n/a

Default Re: Disconnect all users - 05-20-2004 , 10:49 AM



Hi,

The script will be :-

use Master
go
Alter database <dbname> set single_user with Rollback immediate
go
Restore database <dbname> from disk='filename'
go
Alter database <dbname> set multi_user


The above commands will remove all the user connections from the database ,
set to single user and do the restore and after the restore the database is
set to Multi user.

Thanks
Hari
MCDBA

"James" <Homer@jamco> wrote

Quote:
I'm resoring my sql database on a nightly basis, but sometimes it fails as
some users leave there connection to the database up.
Could someone give me the script, or point me in the right direction for a
script that will disconnect all open sessions.

Thanks a lot





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.