Sqlserver-dba.com

SQL Kill connections to a database

SQL Kill  connections on a database , sometimes is the most efficient way forward.I had to copy a whole bunch of MDF\LDF files from a server , but was experiencing some problems regarding user connections.

I was trying to detach using this code:

#####################code start#############################
USE [master]
GO
EXEC master.dbo.sp_detach_db 
@dbname = N'MY_DB', 
@keepfulltextindexfile=N'true'
GO
#####################code end#############################

which was not allowing me to detach . The following code allowed me to clear the connnections and
do the detaching

#####################code start#############################

alter database MY_DB set single_user with rollback immediate  

alter database MY_DB set multi_user with rollback immediate  
#####################code end#############################
Author: Jack Vamvas (http://www.sqlserver-dba.com)


Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact