Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
TransactionScope throwing exception I am using .net core 2.2

In this example I am first creating scope of TransactioScop then opening SQL transaction for one database which is working fine then after the first transaction I am calling commit which will commit SQL transaction then I trying to open call transaction for another database while creating transaction system throwing an exception

as
This platform does not support distributed transactions.


creating transaction is 2 step process first create connection object then open connection for SQL then call begin transaction

C#
c#

using (TransactionScope scop =new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled))
            {
               
                _db1UOW.Begin(); //creating sql transaction
                await _db1UOW.IDenialDetailsRepositorydb1.InsertDenialDetails(denialsDetails);
                await _db1UOW.IRuleDetailsRepositorydb1.InsertRulesDetails(rulesDetails);
                _db1UOW.Commit(); //commitng sql transaction

                _db2UOW.Begin(); //creating sql transaction (but while opening connection object its throwing exception as This platform does not support distributed transactions)
                await _db2UOW.IRuleDetailsRepository.GetRulesDetails();
                await _db2UOW.IDenialDetailsRepository.InsertDenialDetails(denialsDetails);
                var data = await _db2UOW.IRuleDetailsRepository.InsertRulesDetails(rulesDetails);
                _db2UOW.Commit(); //commitng sql transaction
                scop.Complete();
            }


Message "This platform does not support distributed transactions."   

at System.Transactions.Distributed.DistributedTransactionManager.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken)
   at System.Transactions.TransactionInterop.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken)
   at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)
   at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)
   at System.Transactions.EnlistableStates.Promote(InternalTransaction tx)
   at System.Transactions.Transaction.Promote()
   at System.Transactions.TransactionInterop.ConvertToDistributedTransaction(Transaction transaction)
   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
   at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
   at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
   at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
   at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
   at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()


What I have tried:

tried to remove SQL transaction
Posted
Updated 27-May-19 20:17pm

1 solution

In case you are asking: "why is my code trying to create a distributed transaction"

Because you have a connection to two databases inside the same transaction scope. If this is not the intention, place each DB access in its own using statement for the transaction scope.

In case you are asking: Why can't I create a distributed transaction

.NET core does not yet support distributed transactions, and there is no timeline on when (if) this will be done. You can follow it here:
Implement distributed/promoted transactions in System.Transactions. · Issue #13532 · dotnet/corefx · GitHub[^]
In general distributed transactions have fallen out of favor due to scaling problems and often aren't supported in the modern infrastructure anyway, making it a lot less of a priority than you might expect.
 
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