简体   繁体   English

事务日志备份失败,并显示“无法获得独占访问,因为数据库正在使用中”

[英]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.

相关问题 由于正在使用数据库,因此无法获得独占访问权限-但已删除数据库 - Exclusive access could not be obtained because the database is in use - but the database is deleted SQL-Server:错误 - 无法获得独占访问,因为数据库正在使用中 - SQL-Server: Error - Exclusive access could not be obtained because the database is in use 尝试通过T-SQL脚本还原。 由于正在使用数据库,因此无法获得独占访问 - Trying to restore via t-sql script. Exclusive access could not be obtained because the database is in use 从不同数据库备份/还原导致无法获得还原失败的独占访问权限 - Backup/Restore from different database causing Restore failed exclusive access could not be obtained 脱机数据库无法还原:无法获得独占访问 - Offline database can't be restored: Exclusive access could not be obtained 从 .bak 文件恢复 sql server 无法获得独占访问权限 - restore sql server from .bak file Exclusive access could not be obtained SQL Server事务日志备份失败 - Sql Server Transaction Log Backup Fails 备份失败,“正在使用数据库” - Backup fails, “database is in use” BACKUP LOG 无法执行,因为当前没有数据库备份 - BACKUP LOG cannot be performed because there is no current database backup 事务日志还原:数据库中的系统对象是只读的,因此无法更新 - Transaction Log Restore: System objects could not be updated in database because it is read-only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM