If you want to close all connections to a database, you can use the following TSQL code:

 

USE MyDatabase
GO
ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
— Set some options or do some work
GO
ALTER DATABASE MyDatabase SET MULTI_USER
GO

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.