Whenever I restore a backup of my database in SQL Server I am presented with the following error:
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.
Usually to get around this I just restart the server. This was fine when we were developing on our local instance on our dev 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 Subversion was becoming a nightmare. Regardless our simple solution was to put it on a shared server in the office and backup the server occasionally incase someone screwed up the data.
Well I screwed up the data and need 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.
Is there a way to script in T-SQL to be able to take exclusive access or to drop all connections?