title: Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)
body: <p>I have a development database that re-deploy frequently from a Visual Studio Database project (via a TFS Auto Build).</p>
  
  <p>Sometimes when I run my build I get this error:</p>
  
  <pre><code>ALTER DATABASE failed because a lock could not be placed on database 'MyDB'. Try again later.  
  ALTER DATABASE statement failed.  
  Cannot drop database "MyDB" because it is currently in use.  
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>ALTER DATABASE MyDB SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
  </code></pre>
  
  <p>but I still cannot drop the database.  (My guess is that most of the developers have <code>dbo</code> access.)</p>
  
  <p>I can manually run <code>SP_WHO</code> and start killing connections, but I need an automatic way to do this in the auto build.  (Though this time my connection is the only one on the db I am trying to drop.)</p>
  
  <p>Is there a script that can drop my database regardless of who is connected?</p>