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

Loading the SQL Server Management Objects (SMO)

function loadSMO{ $ErrorActionPreference = "Stop" $sqlpsRegistry="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps" try{ if (Get-ChildItem $sqlpsRegistry -ErrorAction "SilentlyContinue") { throw "SQL…

How to Add a Replica into an Existing Availability Group using PowerShell

Overview:0. Add secondary replica to the cluster by running some commands on the availability group…

SQL AlwayOn High Availability Default Port

Internal SQL DEV & QA environments may have SQL listening to the default port of…