0

I use three different web service methods to insert data into three different tables. At first I am calling method1 to insert data into table1. Method1 returns primary key of table1. Then I pass primary key of table to method2 and method3. Both methods insert data into table2 and table3 correspondingly. Suppose if an exception occurs while inserting data into table3 I want to rollback data inserted in table1 and table2. I call the web service methods one after the another. I am using asmx web-services. I searched a lot to find solution but all I managed to find is rollback example in single method call. Is it possible to do sql transactions across c# web services. Please help me to fix this issue. Thanks in advance

1
  • 1
    It is possible - its called distributed transactions, but may be easier just to call a single web service method which atomically modifies all 3 tables in a single SQL transaction. Commented Aug 12, 2015 at 12:23

2 Answers 2

1

I really can not say for certain without seeing the application you are working with but I feel your problem may have exposed a design flaw in your system. SQL Server Distributed Transactions or WCF Transactions may assist you in getting something working I really feel Justin's comment about having a single web service call that modifies all tables involved in the best solution. This enables your business logic to handle the transaction atomically.

Sign up to request clarification or add additional context in comments.

Comments

0

Just try to add these two lines

 try
        {

            transaction.Commit();
        }
        catch (SqlException ex)
        {
            transaction.Rollback();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.