title: How to gain exclusive access to SQL Server 2005 database to restore?
body: <p>Whenever I restore a backup of my database in SQL Server I am presented with the following error:</p>
  
  <pre><code>Msg 3101, Level 16, State 1, Line 1
  Exclusive access could not be obtained because the database is in use.
  Msg 3013, Level 16, State 1, Line 1
  RESTORE DATABASE is terminating abnormally.
  </code></pre>
  
  <p>Usually to get around this I just restart the server. This was fine when we were developing on our local instance on our development machines. But we have a few programmers that need to access the database, and the logistics of having everyone script their changes and drop them into <a href="http://en.wikipedia.org/wiki/Apache_Subversion" rel="nofollow noreferrer">Subversion</a> was becoming a nightmare. Regardless our simple solution was to put it on a shared server in the office and backup the server occasionally in case someone screwed up the data.</p>
  
  <p>Well, I screwed up the data and needed to restore. Unfortunately, I have another co-worker in the office who is working on another project and is using the same database server for development. To be nice I'd like to restore without restarting the SQL Server and possibly disrupting his work.</p>
  
  <p>Is there a way to script in T-SQL to be able to take exclusive access or to drop all connections?</p>