本文介绍了C#事务和存储过程rollbcak的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有三个表,一个掌握一个细节,另一个掌握.
INVOICE_MASTER,INVOICE_DETAIL,PRODUCT_QUNTY.现在我有两个存储过程. sp1在INVOICE_MASTER和UPDATE PRODUCT_QUNTY中进行INSERT,而sp2在INVOICE_DETAIL和UPDATE PRODUCT_QUNTY中进行INSERT.我在所有sp中都使用transaction,commit和rollback.现在,我使用来自应用程序的事务(在C#中)执行那些过程.现在我的问题是,如果回滚发生在c#事务中,那么所有这些事务都是sp,是否会回滚?请提出如何进行此类事务的方法,以寻求适当的解决方案.

Suppose I have three table ,one master one detail and other one.
INVOICE_MASTER, INVOICE_DETAIL, PRODUCT_QUNTY. Now I have two store procedure. sp1 which INSERT in INVOICE_MASTER and UPDATE PRODUCT_QUNTY and sp2 INSERT in INVOICE_DETAIL and UPDATE PRODUCT_QUNTY. I use transaction,commit and rollback in all sp. Now I use transaction from application (in c#) to execute those procedure. Now my question is, if rollback occurred in c# transaction then all those transaction is sp , will be rollback or not? Please suggest how to do this type of transaction for proper solution.

推荐答案

using (TransactionScope scope = new TransactionScope())
        {
// your code
}



使用BeginTrans在sql中启动事务作用域.请在谷歌上搜索这些概念.



Use BeginTrans to start transaction scope in sql. Pls google around these concepts.



这篇关于C#事务和存储过程rollbcak的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:29