troubleshooting Question

My transaction does not abort

Avatar of Arikael
ArikaelFlag for Switzerland asked on
.NET ProgrammingC#
5 Comments1 Solution825 ViewsLast Modified:
Hi experts

I'm trying to use the following code to create a transaction.
Now, to test it the line
TManager.VehiclesTableAdapter.Adapter.Update(ChangedSet.Vehicles);

will always raise a NullReferenceException.
According to http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscope.aspx the transaction should be rolled back as soon as an exception occurs within the transactionscope.
This doesn't happen and the transaction always suceeds.
It only works when I put the Ts.Complete within the try-statement (which kinda makes sense).

Am I misinterpreting something from the msdn-site?
try
                {
                    using(TransactionScope Ts = new TransactionScope())
                    {
                        KrFakturaDataSet ChangedSet = (KrFakturaDataSet)TmpSet;
                        AddressesTableAdapter Adapter = new AddressesTableAdapter();
                        TableAdapterManager TManager = new TableAdapterManager();
                        try
                        {
                            Adapter.Update(ChangedSet.Addresses);
                            TManager.VehiclesTableAdapter.Adapter.Update(ChangedSet.Vehicles);
                            
                        }
                        catch(NullReferenceException e)
                        {
                            MessageBox.Show(e.Message);
                            ChangedSet.RejectChanges();
                        }
 
                        Ts.Complete();
                    }
                }
                catch(TransactionAbortedException e)
                    {
                        MessageBox.Show(e.Message);
                    }
                catch (ApplicationException e)
                {
                    MessageBox.Show(e.Message);
                }
ASKER CERTIFIED SOLUTION
PockyMaster

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros