Exclusive Access Could Not be Obtained Because the Database is in Use
Table of Content
Introduction
In this post, I will show a procedure to resolve the exclusive access could not be obtained as the database is in use from an expert’s point of view. There are ways and solutions mentioned here that any user can trust & execute without facing any hassles at all.
Below is the error that we often encounter when we restore the database since the database is already used by others.
Msg 3101, Level 16, State 1, Line 1
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Steps to Solve Exclusive Access Could Not be Obtained
We will show you a procedure to resolve this issue.
Step-1.
Drop all the connections accessing the database. This can be done either by killing the connections or by putting databases in single-user mode.
Execute SP_WHO2 to find all the connections to the database or we can also use the activity monitor dashboard to find those connections.
Step-2.
Kill all the connections accessing the database using the below script.
Kill SPID — SPID is the session ID of the user process
Step-3.
Setting the database to single-user mode
Use master
GO
ALTER DATABASE <dbname> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE <dbname> FROM DISK = ‘’
GO
ALTER DATABASE <dbname> set multi_user
GO
Along with this, users can also learn how to rollback a transaction in SQL Server database. Make sure that you pay attention while executing these commands as the wrong command may have severe consequences. If users will execute all the steps just like how the article says, then the task can be much easier. In addition, users can get maximum benefits from their SQL server smartly.
Regards
Ganapathi Varma
Senior SQL Engineer, MCP
Conclusion
With this, let’s conclude this article in the hope that all the troubled users can get their answers now. If you have any more doubts like exclusive access could not be obtained because the database is in use, contact to the support team to know more.