On SQLServerCentral.com tonight, I found a really neat little SQL procedure written by Brian Knight that allows you to disconnect any users currently connected to a specific database.

Quickly Disconnect Users

I needed this script so I could disconnect all of the CRM users so I could perform some maintenance on the CRM databases.
 

 

4 Responses to Quickly Disconnecting SQL Users from a Database

  1. The following command will disconnect all users and make sure that users cannot logon while you are making your changes…

    ALTER DATABASE dbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE

    You can allow access again with the MULTI_USER option

  2. mitch says:

    Excellent suggestion! Thanks Darrel.

  3. Clyde says:

    How do you force[diconnect] all connected users from the database, I'm trying to delete a database and it gives me an error saying that there is a connected user and it is in a single_user state

  4. nan says:

    ALTER DATABASE uasdb SET multi_USER WITH ROLLBACK IMMEDIATE

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>