gpt4 book ai didi

sql-server-2008 - 当前事务无法提交,不支持写入日志文件的操作。回滚事务

转载 作者:行者123 更新时间:2023-12-04 07:01:22 28 4
gpt4 key购买 nike

从下面的代码中,我们在 raiseerror 处遇到异常 - 当前事务无法提交并且无法支持写入日志文件的操作。回滚事务。

IF @insertOrUdate = 'D'
BEGIN

-- DescType depends on CorrectionType and is also a protected sync table,
-- it needs to be cleared out before we can remove this type
IF EXISTS(
SELECT TOP 1 *
FROM [dbo].[DescType]
WHERE
[CorrectionTypeId] = @correctionTypeId

)
BEGIN
PRINT 'raise error'
RAISERROR('Dependent Desc Role Type Rollups must be removed prior to removing a type that they depend on', 16, 1)

PRINT 'after raise error'
END

-- Delete protected Sync record
DELETE FROM [dbo].[CorrectionType] WHERE [CorrectionTypeId] = @correctionTypeId;

END;

最佳答案

因为你有 SET XACT_ABORT ON' when you do your RAISERROR() you're setting the XACT_STATE` 为 -1,这意味着您不能对数据库执行任何更多可提交的工作,您只能回滚您的事务。

使用 temp procs 和上述触发器之一的示例:

create proc #a 
as
--This is the proxy for the parent proc
begin try
begin tran
exec #b
commit tran
end try
begin catch
if @@trancount > 0 rollback
select error_message();
end catch

go

create proc #b
as
set xact_abort on;

begin try;
DISABLE TRIGGER [dbo].[trg_dml_CorrectionType_InsteadOfDelete] ON [dbo].[CorrectionType];
--Check state
select xact_state() one;

raiserror('Error!', 16,1)

--This one doesn't run of course
select xact_state() two
end try
begin catch
select xact_state() three;
select error_message() as msgprior;

ENABLE TRIGGER [dbo].[trg_dml_CorrectionType_InsteadOfDelete] ON [dbo].[CorrectionType];

--This doesn't run either, new error
select xact_state() four;

--if @@trancount > 0 rollback transaction;
declare @error nvarchar(2500)
select @error = error_message()
raiserror(@error, 16,1);
end catch

GO

exec #a

你有几个选择,我相信:
  • 将此过程的 XACT_ABORT 设置为 OFF。那应该处理
    此特定场景的 XACT_STATE 问题,以及您的 ROLLBACK
    应该处理您的触发问题。
  • 移动您的启用/禁用触发器
    到您的父进程并在事务之外处理它们
    完全。他们不需要依赖于你的其他行动
    这个子进程;无论如何,您总是禁用/启用它们。
  • 关于sql-server-2008 - 当前事务无法提交,不支持写入日志文件的操作。回滚事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16033375/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com