Many times we need all sql server connections to be closed except the connection in which our current query is running. For that we can try the following methods.
a)Search and kill all the connected users.
b)Stop and restart the database server, then issue the command.
c)Take the database offline etc.This is really a pain though has to be done.
The best way to do it by setting the database in single user by following commands:
ALTER DATABASE database_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Do the job and set it back to multi user
ALTER DATABASE database_name SET MULTI_USER WITH NO_WAIT