Solved

TransactionScope rollback.

Posted on 2011-03-24
1
868 Views
Last Modified: 2012-05-11
Hi

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
1
2
1

but the actual output was
1
2
2

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>();
            foo.Add("a");
            Console.WriteLine("Before Transaction: "+foo.Count);
            
            try
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {                    
                    foo.Add("b");                    
                    Console.WriteLine("During Transaction: "+foo.Count);
                }
            }
            catch 
            {
            }

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

Open in new window

0
Comment
Question by:mkarthik415
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 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:
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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