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
You can force the database offline and drop connections with:
EXEC sp_dboption N'yourDatabase', N'offline', N'true'
Or you can
ALTER DATABASE [yourDatabase] SET OFFLINE WITH
ROLLBACK AFTER 60 SECONDS
Rollback specifies if anything is executing. After that period they will be rolled back. So it provides some protection.
Sorry I wasn't thinking/reading right. You could bing back online and backup. There was also a post on Stack Overflow on a T-SQL snippet for dropping all connections rather than binging offline first: Hidden Features of SQL Server