If you want to drop all connections to a database by using T-SQL, connect Microsoft SQL Server Management Studio to the master database, open a new query editor window and execute the following T-SQL code:

 

/*
    Drop all connections to a database
*/

-- Take database offline
alter database [MyDatabase]
set offline with rollback immediate

-- Take database online
alter database [MyDatabase]
set online

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.