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…

Microsoft SQL Server Replication Setup Error Number MSSQL_REPL2110 and Resolution

Symptom: The distribution agent failed to create temporary files in 'C:\Program Files\Microsoft SQL Server\130\COM' directory…

Microsoft SQL Cloning Database to a Different DB Name

# User defined variables $sourceSqlServer='DEV-SQL01' $sourceDatabaseName='TEST_MSCRM' $sourceSaCredential=$(get-credential) $destinationSqlServer='DEV-SQL01' $destinationDatabaseName='Test_MSCRM' $destinationSaCredential=$(get-credential) function copyDatabase{ param( $sourceSqlServer, $sourceDatabaseName,…