Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C#
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
good
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 (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:
 
using (TransactionScope scope = new TransactionScope())
        {
// your code
}
 
Use BeginTrans to start transaction scope in sql. Pls google around these concepts.
  Permalink  
v2
Comments
avikGhosh87 at 7-Oct-12 13:42pm
   
Thankx all
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 OriginalGriff 394
2 thatraja 370
3 Sergey Alexandrovich Kryukov 329
4 CPallini 179
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2014
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