I created a class to synchronize data between two different data sources. This synchronization is divided into several parts (and methods). Each method has its own TransactionScope, and the methods are run sequentially.
Every time I run this code, I get the following error message:
"The operation associated with the current connection has completed but has not been deleted. The transaction must be deleted before the connection is used to execute SQL statements."
The following code is an example of such a method with TransactionScope:
private void SomeMethod()
{
try
{
using (var _transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
using (SqlConnection _connection = new SqlConnection(connectionstring))
{
_connection.Open();
DoSomething()...
}
_transactionScope.Complete();
}
}
catch (TransactionAbortedException e)
{
nlog.Error(string.Format("The transaction has been aborted: {0}", e.Message));
throw e;
}
catch (Exception e)
{
throw e;
}
}
It seems that calling "_ transactionScope.Complete ()" is not enough to kill the transaction. Does anyone know what I'm doing wrong?
Thanks in advance!
UPDATE
. , . :
try
{
using (TransactionScope _transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
using (SqlConnection _connection = new SqlConnection(connectionstring))
{
_connection.Open();
using (TransactionScope _transactionScope = new TransactionScope(TransactionScopeOption.Suppress))
{
}
_transactionScope.Complete();
}
}