Kill All Connections on a Database

This seems to be the easiest way to kill all connections (sessions) on a SQL Server database:

[cc lang=”sql”]
ALTER DATABASE database_name

SET SINGLE_USER

WITH ROLLBACK IMMEDIATE
[/cc]

After executing the above, it will put the database in single user mode. So you then need to remove single user mode using:

[cc lang=”sql”]
EXEC sp_dboption ‘database_name’, ‘single user’, ‘FALSE’
[/cc]

Featured Articles

 Site Author

  • Thanks for visiting!
css.php