Posted On October 28, 2020

T-SQL Msg 3101 Exclusive access could not be obtained because the database is in use

kimconnect 0 comments
blog.KimConnect.com >> Database >> T-SQL Msg 3101 Exclusive access could not be obtained because the database is in use
Symptom:
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.

Completion time: 2012-10-27T20:46:07.0030490-07:00
Resolution:

Assuming that the database name is TEST_MSCRM and it’s backup file is B:\Backup\TEST_MSCRM.bak’

USE [master]
GO

ALTER DATABASE [TEST_MSCRM]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE; --This rolls back all uncommitted transactions

RESTORE DATABASE [TEST_MSCRM]
FROM DISK = N'B:\Backup\TEST_MSCRM.bak' WITH FILE = 1,
MOVE N'mscrm' TO N'D:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\TEST_MSCRM.mdf',
MOVE N'mscrm_log' TO N'D:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\TEST_MSCRM.ldf',
NOUNLOAD, REPLACE, STATS = 5;

ALTER DATABASE [TEST_MSCRM] SET MULTI_USER
GO

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Microsoft SQL Database Stuck in Restoring Mode

These are the possible resolutions from highest to lowest recommendations -- Normal method of restoring…

SQL: Using PowerShell to Check if a Table, View, or Stored Procedure Exists

#Usage # set variables $sqlServer='sql-server04' $databaseName="Test_Database" $objectType='view' $objectName='[dbo].[Test_View]' $saCred=get-credential # Call function checkDatabaseObject $sqlServer $databaseName…

PowerShell: Obtaining SQL Database Default Paths

# This function returns an array of 3 string values reflecting default Data, Log, and…