I am using ‘TransactionScope’, and I need to just do some DML within the C# Code, which I have successfully.
I need to find out that what is the status of the Transaction, that is has it completed successfully or not ?
Because on the basis of the Transaction Status, if the transaction is complete then I need to perform a redirect to another page, otherwise if the transaction is not completed successfully then I need to show the error on the page.
I want to redirect after the following:-
scope.Complete();
scope.Dispose();
Please help me in this regards.
If you visit the MSDN page for
TransactionScope, you would find this well-documented example:The comment that contains the most value is this one:
So, if no exceptions are thrown, you can continue on. Put your redirect after
scope.Complete(). If an exception is thrown, the transaction failed and has automatically been rolled back. You could double-check the transaction status (as others have posted) after the call toComplete()and before you redirect, viaTransaction.Current.TransactionInformation.Status: