Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code shown here worked fine without any error on quality site, but the same code is causing an error

The Transaction has aborted

on the production site.

The error occurs on dispose of the scope. Please help me resolve this issue.

I did check:

Network DTC Setting on server and database server
Both sites (Quality and Production) are on same Server (Server A) and database also on same server (Server B)
Code:


option.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
option.Timeout = TimeSpan.FromMinutes(5);

using (_objTransactionScope = new TransactionScope(TransactionScopeOption.Required, option))
{
    //..Open Connection
    //..Process the Document
    //..Update Additional information in Table2 about document(Delete/Insert)   
    //..Update Location Information in Table3 about document(Delete/Insert)
    //..Delete the Document in Table4 in Differant Database on Differant Server(WCF Service)
    //..Update the Checksum of the Document and Metadata in Table1
    //..Delete Lock Entry From Table5   
    //..Close Connection
    //..Commit Transaction Scope
}


What I have tried:

I did check:

Network DTC Setting on server and database server
Both sites (Quality and Production) are on same Server (Server A) and database also on same server (Server B)
Posted
Updated 14-Nov-21 5:09am

1 solution

Quote:
Both sites (Quality and Production) are on same Server (Server A) and database also on same server (Server B)

First off, that worries me: development should never have any access to production servers, and especially not production DB servers.
You should always develop and test against a separate dev DB server (often SQL Server Express) as a tiny error can easily damage or destroy the production DB.

Your ordering is wrong: you cannot commit the transaction after you close the connection, and that will probably cause the problem you have noticed.

Instead, make the connection outside (with a using block) so it the tha last thing to be terminated, and commit as the last thing you do inside it. That way, any failure in other code will always close your transaction - aborting all updates - before the connection is closed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900