SQL: Exclusive access could not be obtained because the database is in use

You want to restore a database on Microsoft SQL Server but ended with below error,

ITLE: Microsoft SQL Server Management Studio
------------------------------

Restore of database 'DEV' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.SmoExtended)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.2100.60+((SQL11_RTM).120210-1917+)&LinkId=20476

Solution

You can perform the following step options,

Option 1 (set the database into single user mode)

ALTER DATABASE SID SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Option 2 (kill the user session)

sp_who2
kill [SPID]

Option 3 (restart your database / restart the operating system)

You May Also Like

Leave a Reply?