Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted

Transaction is RDBMS concept though you can set it through c# code. In this way, if you rollback your transaction in C#, the same will affect in sp's as well.

In other words you can define transaction scope in sp, DAL (ADO.net), linq etc. But these are the places where you can define your transaction scope which actually belongs to the RDBMS.

To use in C# simply use:

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


Use BeginTrans to start transaction scope in sql. Pls google around these concepts.
 
Share this answer
 
v2
Comments
avikGhosh87 7-Oct-12 13:42pm    
Thankx all
Because they are effectively nested transactions, any rollback in the C# code will override a commit in the SP.
So if you rollback for any reason in the C#, the SP transactions will be discarded.

There is no problem with having multiple transactions like this: many of your developers do not need to know the inner workings of the SP and whether it contains a transaction at all. The transactions could well be rolling back for completely different reasons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900