When performing a full restore over an existing database, SQL Backup sometimes reports that the database cannot be restored because it is currently in use, like shown below:
This error shows not only during restore backup, also for drop database or alter database as well.
In this situation, database administrator needs to disconnect all the connected users from a SQL Server Database to get exclusive access of the database. In the situation where a full restore is blocked because users are currently connected to the database, the best solution to this problem is to take the database offline prior to running the restore, as this is the easiest way to kill all connections to the database.
Before Restore Attempt
Database administrator can execute the below mentioned TSQL command to get a Single User access to a database.
SINGLE_USER WITH ROLLBACK IMMEDIATE command is used so that only one user can connect to the database at a time.
alter database DB_NAME set offline with rollback immediate;
Database administrator can execute the below mentioned TSQL command to give Multiple User access to a database.
MULTI_USER command is used by any number of users who have rights to connect to the database that will be able to connect to the database.
alter database DB_NAME set online with rollback immediate;
So now all authenticated database users can connect to the database again.