Click here to Skip to main content
12,953,700 members (43,771 online)
Rate this:
Please Sign up or sign in to vote.
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 6-Oct-12 22:18pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 (, 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:

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

Use BeginTrans to start transaction scope in sql. Pls google around these concepts.
avikGhosh87 7-Oct-12 13:42pm
Thankx all
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100