问题描述
在SQL Server中,是否有与c#的try..catch...
块中的finally
子句相似的东西?
In SQL Server, is there something similar to finally
clause in try..catch...
block of c# ?
我的意思是,我在SQL Server事务中使用BEGIN TRAN, END TRAN, COMMIT TRAN, ROLLBACK TRAN
等,并且无论是否成功或失败或事务,都需要执行需要触发的部分或某些动作.
I mean, I am using BEGIN TRAN, END TRAN, COMMIT TRAN, ROLLBACK TRAN
etc in a SQL Server transaction and want a section or some set of actions that needs to fire irrespective of success or failure or transaction.
有解决方案吗? (类似于对OOPS语言的try/catch的finally阻止).
Is there a solution for that? (similar to finally block on try/catch of OOPS languages).
预先感谢
推荐答案
没有任何任何可以100%可靠地不管成功或失败"运行.不管您是在谈论C#程序的"finally"子句,还是SQL Server上的BEGIN TRY ... END TRY BEGIN CATCH ... END CATCH结构.
There isn't anything that will run "irrespective of success or failure" with 100% reliability. It doesn't matter whether you're talking about the "finally" clause of a C# program, or a BEGIN TRY...END TRY BEGIN CATCH...END CATCH stucture on SQL Server.
问题在于,此类接线端子无法在所有可能的故障模式下执行.每个可能故障模式都必须包括软件,硬件和网络故障.如果您的客户是政府,那么它可能还必须包括导弹袭击.
The problem is that terminal blocks like these can't execute under every possible failure mode. Every possible failure mode has to include software, hardware, and network failures. If your client is the government, it probably has to include missle attacks, too.
必须引用经典的TheDailyWTF .
这篇关于SQL Server事务中的最终条款?不管成功或失败,都会执行什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!