RSS

How can I kill db’s connections (SINGLE_USER) ??

26 Oct

Kill db’s connections:

What will you do if you want to kill all connections related to your database ??. In other words, what will you do if you want to make the database available to you only ??

In this post we will talk about SINGLE & MULTIPLE users policy in SQL server … Follow me:

  • To make the database available to you only (SINGLE USER state), there are two options. Before showing options you have to know that other users may be prepare some actions or operations in the same database, here you have to deiced that if you will ignore these actions and operations immediately but wait for sometime.
  • The first one to take the database for yourself only: with an immediate ignoring these actions and operations write the following T-SQL command:

ALTER DATABASE [MyDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

  • The second one to take the database for yourself only: with waiting for sometime (n of seconds) and then ignoring these actions and operations write the following T-SQL command:

ALTER DATABASE [MyDatabaseName] SET SINGLE_USER WITH ROLLBACK AFTER 50;

— 50: means a fifty seconds

  • To make the database available to all users again, you have to run the following T-SQL command:

ALTER DATABASE [MyDatabaseName] SET MULTI_USER;

 
Leave a comment

Posted by on October 26, 2011 in MS SQL Server

 

Tags: , , , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: