[英]Transaction Log Backup fails with "Exclusive access could not be obtained because the database is in use"
I am attempting a Log Shipping failover test and the step which is intended to put the database into restoring mode is failing with the error "Exclusive access could not be obtained because the database is in use".我正在尝试日志传送故障转移测试,而旨在将数据库置于恢复模式的步骤失败,并显示错误“无法获得独占访问,因为数据库正在使用中”。
The action was carried out through SSMS selecting "Transaction Log" and also selecting "backup the tail of the log" under Media Options which should leave the database in "restoring mode".该操作是通过 SSMS 执行的,选择“事务日志”并在“媒体选项”下选择“备份日志的尾部”,这将使数据库处于“恢复模式”。
After the failure I attempted to put the database into single user mode first and also take it offline but both commands didn't work (or fail).失败后,我尝试首先将数据库置于单用户模式并将其脱机,但两个命令都不起作用(或失败)。
I have repeated the action against a test database and that worked with no problem.我已经对测试数据库重复了该操作,并且没有问题。 The T-SQL is below: T-SQL 如下:
BACKUP LOG [TESTDB] TO DISK = N'U:\MSSQL\Backup\TESTDB.bak' WITH NO_TRUNCATE , NOFORMAT, NOINIT, NAME = N'TESTDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 10, CHECKSUM
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'TESTDB' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'TESTDB' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''TESTDB'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'U:\MSSQL\Backup\TESTDB.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
I also checked for any blocking or running transactions but nothing showed up.我还检查了任何阻塞或正在运行的事务,但没有任何显示。
Any ideas anyone?任何人的想法?
A log backup that leaves the target database in RESTORING is called a " Tail Log Backup ".将目标数据库保留在 RESTORING 中的日志备份称为“ 尾日志备份”。 And taking the database offline requires terminating all other connections to the database.使数据库脱机需要终止与数据库的所有其他连接。 Like this:像这样:
use testdb
go
alter database testdb set single_user with rollback immediate
go
use master
BACKUP LOG [TESTDB] TO DISK = N'c:\temp\TESTDB.bak' WITH NO_TRUNCATE , NOFORMAT, NOINIT, NAME = N'TESTDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 10, CHECKSUM
GO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.