sqlserver中的rollback transaction要跟COMMIT TRAN成对存在吗?
我这种结构写怎么报错了EXECUTE后的事务计数指示BEGIN和COMMIT语句的数目不匹配。上一计数=2,当前计数=3。BEGINTRANtran1SAVETRANtr...
我这种结构写怎么报错了
EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配。上一计数 = 2,当前计数 = 3。
BEGIN TRAN tran1
SAVE TRAN tranpoint --保存事务点
SET @TRANCOUNT=@@TRANCOUNT
PRINT '进入子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
begin try
IF (@OrderType='1')
BEGIN --1
IF @OrderStatus=4
BEGIN--2
IF asas=1
BEGIN--3
END--3
ELSE
BEGIN--3
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
END--3
END--2-
ELSE
BEGIN--2
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
END--2
END--1
----------提交事务------------------
end try
begin catch
/**根据是否有错误,确定事务是提交还是回滚*/
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
end catch
print '成功,提交事务,写入硬盘'
commit transaction tran1
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '提交子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return 1 展开
EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配。上一计数 = 2,当前计数 = 3。
BEGIN TRAN tran1
SAVE TRAN tranpoint --保存事务点
SET @TRANCOUNT=@@TRANCOUNT
PRINT '进入子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
begin try
IF (@OrderType='1')
BEGIN --1
IF @OrderStatus=4
BEGIN--2
IF asas=1
BEGIN--3
END--3
ELSE
BEGIN--3
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
END--3
END--2-
ELSE
BEGIN--2
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
END--2
END--1
----------提交事务------------------
end try
begin catch
/**根据是否有错误,确定事务是提交还是回滚*/
print '失败,回滚事务.'
rollback transaction tranpoint
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '回滚子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return -1
end catch
print '成功,提交事务,写入硬盘'
commit transaction tran1
SET @TRANCOUNT=(select @@TRANCOUNT)
PRINT '提交子事务后全局@@TRANCOUNT:'+CAST(@TRANCOUNT AS VARCHAR(50))
return 1 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询