Peter Schulz-485500 (11/18/2013)
I have a bit of a hard time disconnecting everybody. But I'll try this next.
Disconnecting everyone and everything is the easy part. Just make sure that you don't lose the connection after you run the following or some nasty ol' web service will snatch up the only connection available.
USE [master]
GO
ALTER DATABASE [YourDatabaseNameHere] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
If you're sure that high prived users/apps/servers aren't going to barge in, then you could move to a safer multi-connection mode that still keeps most people out and lets you back in if you lose the connection.
USE [master]
GO
ALTER DATABASE [YourDatabaseNameHere] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE;
When you're done, let everyone else back in.
USE [master]
GO
ALTER DATABASE [YourDatabaseNameHere] SET MULTI_USER;
--Jeff Moden
Change is inevitable... Change for the better is not.