At this moment, we are going to discussed about: How to Kill all sessions in MSSQL using database. Before an existing database are often restored, there ought to be connections using the database in question. If the database is presently in use the RESTORE command fails with error on below:
Msg 3101, Level 16, State 1, Line 2
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.

To avoid that error, we'd like to kill all sessions using the database in MSSQL. All sessions using the database are often queries using system hold on procedure sp_who2 or using sys.dm_exec_sessions DMV:
SELECT   session_id
FROM     sys.dm_exec_sessions
WHERE    DB_NAME(database_id) = 'SqlAndMe'

You need to terminate every of the sessions came back one by one by using KILL command. If there are sizable amount of sessions to kill, otherwise you got to try this on a routine basis it gets boring to do it this manner. you'll be able to *automate* this using below script, that takes database name as input, and kills all sessions connecting to that.
USE [master]
GO 
DECLARE @dbName SYSNAME
DECLARE @sqlCmd VARCHAR(MAX) 
SET @sqlCmd = ''
SET @dbName = 'SqlAndMe' -- Change database NAME
 SELECT   @sqlCmd = @sqlCmd + 'KILL ' + CAST(session_id AS VARCHAR) +
         CHAR(13)
FROM     sys.dm_exec_sessions
WHERE    DB_NAME(database_id) = @dbName 
PRINT @sqlCmd
--Uncomment line below to kill
--EXEC (@sqlCmd)

Hope this tutorial works for you!