separate try-catch statements

This is a related question and i got a good explanation.  I have one more question. My code is below.I have 5 database calls to save. I have ONE try-catch statement. When the error is thrown, I dont know which method is throwing it. I have this in a TranscationScope so if any occurs, i want to roll back...so, for example, if the first 2 saves don't occur, i dont want to save the rest...i dont want to have orphaned records....

How can I wrap this in individual try-catch to capture exactly which step throw the error AND still keep the TransactionScope? doble?
using (TransactionScope scope = new TransactionScope())
        {
            try
            {
                Sign_UpData sd = new Sign_UpData();
                int businessNameId = SaveDescription(sd);
                SaveContactPerson(sd, businessNameId);
                SaveOfficeLocation(sd, businessNameId);
                SaveHCProviderInformation(sd,businessNameId);
                SaveOfficerUserName(sd, businessNameId);

                scope.Complete();
            }

            catch (TransactionAbortedException ex)
            {
                Common common = new Common();
                common.Log("New user", "Signup", string.Concat(ex.Message, "Stack Trace Starts here:", ex.StackTrace, "inner exception starts here: ", ex.InnerException ));
            }
            catch (SqlException ex)
            {
                Common common = new Common();
                common.Log("New user", "Signup", string.Concat(ex.Message, "Stack Trace Starts here", ex.StackTrace, "inner exception starts here: ", ex.InnerException));
            }



        }

Open in new window

LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kenneth BrownResearch AssociateCommented:
In the try declare an int stepcompleted = 0;
Increment it after each call.
Check its value if an exception is called.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kenneth BrownResearch AssociateCommented:
oops - the variable is declared in the transactionscope - not the try block, otherwise its out of scope by the time you catch the exception.
CamilliaAuthor Commented:

I dont understand this:
>>Check its value if an exception is called.

Check the value for what? And, I dont need to wrap each call in a try-catch?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.