How to close existing connections to a DB

sql, sql-server

Solution

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!

Problem

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

Original source

Related problems