How to close existing connections to a DB


I want to close the existing connections to an MS SQL Server so that I can do a restore on that database programatically.

This question is tagged with sql sql-server

~ Asked on 2012-04-30 17:39:35

The Best Answer is


This should disconnect everyone else, and leave you as the only user:

alter database YourDb set single_user with rollback immediate

Note: Don't forget

alter database YourDb set MULTI_USER

after you're done!

~ Answered on 2012-04-30 17:47:23


in restore wizard click "close existing connections to destination database"

in Detach Database wizard click "Drop connection" item.

~ Answered on 2015-02-28 08:45:42

Most Viewed Questions: