简体   繁体   中英

Oracle.ManagedDataAccess.Core - Transaction Scope Issue

I'm trying to convert a project to .Net Core but I have hit a stumbling block.

When I open two different oracle connections within a transaction scope, the below error is received:

"Operation is not supported on this platform."

"   at OracleInternal.MTS.MTSRMManager.CCPEnlistDistributedTxnToSysTxn(OracleConnectionImpl connImpl, Transaction txn, MTSTxnRM txnRM, MTSTxnBranch txnBranch)

   at OracleInternal.MTS.MTSRMManager.CCPEnlistTransaction(OracleConnectionImpl connImpl, Transaction transaction, MTSTxnRM txnRM, MTSTxnBranch txnBranch)

   at OracleInternal.ConnectionPool.PoolManager`3.GetEnlisted(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria)

   at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)

   at Oracle.ManagedDataAccess.Client.OracleConnection.Open()"

The code below causes this error when opening the second connection. In addition, this does not happen on the standard framework Oracle.ManagedDataAccess. It only happens on the Oracle.ManagedDataAccess.Core version.

My guess is that it looks to be something with connection pooling, but I could use some help.

If you use the same connection string for each connection there is no problem. Only occurs when you have two different connections.

    using (TransactionScope scope = new TransactionScope())
    {
        using (var conn = new OracleConnection(connectionString1))
        {
              conn.Open();
        }

        using (var conn = new OracleConnection(connectionString2))
        {
             conn.Open(); //Exception occurs here
        }

       scope.Complete();
    }

As per the docs :

ODP.NET Core does not support Distributed Transactions.

Hence why "Operation is not supported on this platform."

If you use the same connection string for each connection there is no problem. Only occurs when you have two different connections.

If you use only a single connection then you will be fine, since you aren't using a Distributed Transaction. Once you have more than one though, a Distributed Transaction will be involved (which ODP.NET Core does not support). This is consistent with what you are seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM