TransactionScope rollback.

Posted on 2011-03-24
Medium Priority
Last Modified: 2012-05-11

How to rollback a TransactionScope. I tried adding new elements List in a transaction using TransactionScope and never called the complete method. Even after that the methods inside the Transaction are executed and are not rolled back. Below is the sample code.

I was expecting output to be

but the actual output was

Could anyone tell me how to get the expected output using the below code.

Thank You

static void Main(string[] args)
            List<string> foo = new List<string>();
            Console.WriteLine("Before Transaction: "+foo.Count);
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                    Console.WriteLine("During Transaction: "+foo.Count);

            Console.WriteLine("After Transaction: " + foo.Count);            

Open in new window

Question by:mkarthik415
1 Comment
LVL 23

Accepted Solution

wdosanjos earned 2000 total points
ID: 35211415
TransactionScope is related to database transactions and it has no impact on collections (List<T> in your example).

More about TransactionScope here:

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question