When taking a database offline you may find the offline process takes a long time or may fail due to existing connections. You can use the following SQL to identify user sessions that are connected to a particular database:
{code lang:sql showtitle:false lines:false hidden:false}USE MASTER
SELECT * FROM sysprocesses WHERE dbid = DB_ID(‘APPV’){/code}
Using the SPID from the output above kill any identified session by using the simple SQL below:
{code lang:sql showtitle:false lines:false hidden:false}kill <session ID>{/code}