Transaction Support

Topics: July and December Releases Forum
Mar 5, 2007 at 8:47 AM
I was working on the WSSF Data repository classes, while using it in Business Logic there seem no transaction support in it, whether at database or process level , can anyone please help me in this Regard.
Mar 5, 2007 at 7:06 PM
There is no trasanction tooling support but you can find some guidance and user experiences in this thread: Transactions.

Charly
Mar 6, 2007 at 5:43 AM
I tried using TransactionScope, while adding multiple rows but if it fails in between it doesnot rolls back. Do you have any idea what is the issue in it.
Mar 6, 2007 at 3:02 PM
You can try adding the following code to your business class where your call your derived Repository class.

using (TransactionScope ts = new TransactionScope())
{
    // Add your repository classes here
    ClubMemberRepository repository = new ClubMemberRepository("CohoWinery");
    repository.Add(member);
    ts.Complete();
}
It's very important that you don't forget adding the call to Complete() method in order to set the vote for commit the transaction.
The "using" statement will be calling Dispose at the end of the block so the "ambient" transaction will be commited only and only if the Complete() method was called. If an error was thrown before reaching the Complete() method, then a rollback will be performed at the end of the using block since no commit vote was set.

Charly
Mar 7, 2007 at 7:52 AM
Yes, i tried using this TransactionScope class, but i guess it needs DTS to be enabled, which is going a little out of scope, i was concentrating more on the Database transaction be be controlled from the Business logic rather than DTS itself, anyways thanx for your reply.

Murtaza
Mar 7, 2007 at 12:58 PM
If you are using SQL 2005, it will not use Distributed Transactions since it supports "promotable transactions" and is smart enough to realize that a distributed transaction is not needed. For further info, read System.Transactions for Sql Server 2000 and Sql Server 2005 - TransactionScope and SqlTransaction.
As stated there;
If you are using Sql Server 2000, the local transaction automatically becomes promoted to a distributed transaction managed by MSDTC, which is unecessary in this case and will cause a performance hit.

Charly
Mar 8, 2007 at 6:14 AM
Yes i know that but unluckyly i am using SQL Server 2000