These 2 snippets of T-SQL code will disconnect the users (application) and set the database offline. The usefulness of disconnecting the users is so that you’re actually able to set the database as offline.
Note: YOUR_DATABASE will have to be replaced by the name of the database you wish to set as offline.
-- set database offline alter database YOUR_DATABASE set single_user with ROLLBACK IMMEDIATE; -- all connections are disconnected go alter database YOUR_DATABASE set offline; go
-- set the database online alter database YOUR_DATABASE set online; -- database in single-user mode go alter database YOUR_DATABASE set multi_user; -- allow multi-user access go
// CrashMAG