begin tran
begin try
select case when 1=0 then 0.0 else '' end --this will not work
end try
begin catch
--error has occured. But it doesnt matter. We want to continue anyway
end catch
select 1 --do something else
commit --unfortunatelly this producess error "The current transaction cannot be committed and cannot support operations that write to the log file"
我可以做什么来提交交易? 我知道,
select case when 1=0 then 0.0 else '' end
不正确。这就是为什么它位于 try/catch 块中(在实际情况下,这是由管理员定义的查询)。但我想提交其余的操作。
编辑:// 如果“不正确的查询”是例如,代码可以按我想要的方式工作
select 1/0
begin tran
begin try
select 1/0-- this will not work
end try
begin catch
--error has occured. But it doesnt matter. We want to continue anyway
end catch
select 1--do something else
commit --commit is done without any errors
您可以尝试在提交或退出之前检查事务状态..
begin tran
begin try
select case when 1=0 then 0.0 else '' end --this will not work
end try
begin catch
--error has occured. But it doesnt matter. We want to continue anyway
end catch
select 1 --do something else
IF (XACT_STATE()) = -1
rollback tran
IF (XACT_STATE()) = 1
commit tran