Page 1 of 1

Error with transactions : The current TransactionScope is already complete.

Posted: Tue 05 Jun 2018 08:08
by mouadh
Hi all,

i got this exception when executing a simple read query using entity framework on our Postgre Db,
in the code, that throw this exception, i dont use transactions
the code do not fail systematically but randomly

this the stack trace :

Code: Select all

{
  "Depth": 0,
  "ClassName": "System.Data.Entity.Core.EntityException",
  "Message": "The underlying provider failed on Open.",
  "Source": "EntityFramework",
  "StackTraceString": "   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()\r\n   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)\r\n   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()\r\n   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()\r\n   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)\r\n  ......,
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": {
    "Name": "Open",
    "AssemblyName": "EntityFramework",
    "AssemblyVersion": "6.0.0.0",
    "AssemblyCulture": "",
    "ClassName": "System.Data.Entity.Core.EntityClient.EntityConnection",
    "Signature": "Void Open()",
    "MemberType": 8
  },
  "HResult": -2146233087,
  "HelpURL": null
},
{
  "Depth": 1,
  "ClassName": "System.InvalidOperationException",
  "Message": "The current TransactionScope is already complete.",
  "Source": "System.Transactions",
  "StackTraceString": "   at System.Transactions.Transaction.get_Current()\r\n   at Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)\r\n   at Devart.Common.DbConnectionFactory.b(DbConnectionBase A_0)\r\n   at Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)\r\n   at Devart.Common.DbConnectionBase.Open()\r\n   at Devart.Data.PostgreSql.PgSqlConnection.Open()\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()",
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": {
    "Name": "get_Current",
    "AssemblyName": "System.Transactions",
    "AssemblyVersion": "4.0.0.0",
    "AssemblyCulture": "",
    "ClassName": "System.Transactions.Transaction",
    "Signature": "System.Transactions.Transaction get_Current()",
    "MemberType": 8
  },
  "HResult": -2146233079,
  "HelpURL": null
}
in the Db the transaction are enabled,
i set the

Code: Select all

max_prepared_transactions = max_connections =100

Code: Select all

Postgre Db version : 9.4

Devart.Data.dll v 5.0.1313.0
Devart.Data.PostgreSql.dll v 7.4.521.0
Devart.Data.PostgreSql.Entity.dll v 7.4.521.6
any idea why/when this exception happen ?

Respectfully,
Mouadh

Re: Error with transactions : The current TransactionScope is already complete.

Posted: Thu 07 Jun 2018 18:48
by Shalex
1. Please send us a working project (as simple as it can be) and specify the exact steps we should follow for reproducing the error.

2. Tell us an approximate time to wait for the error to occur.

Re: Error with transactions : The current TransactionScope is already complete.

Posted: Fri 08 Jun 2018 13:41
by mouadh
The error occurred randomly , i can not provide a sample to reproduce the bug
if i remove transaction use from our code, the problem is fixed

we are using TransctionScope in our code

Code: Select all

new TransactionScope(TransactionScopeOption.Required,
                new TransactionOptions
                {                   
                    Timeout = TransactionManager.MaximumTimeout,                   
                    IsolationLevel = IsolationLevel.Snapshot
                },
                TransactionScopeAsyncFlowOption.Suppress);

Re: Error with transactions : The current TransactionScope is already complete.

Posted: Mon 11 Jun 2018 14:02
by mouadh
problem fixed by setting `TransactionScopeAsyncFlowOption.Enabled` when creating the transactionscope

https://particular.net/blog/transaction ... h-the-flow

Re: Error with transactions : The current TransactionScope is already complete.

Posted: Tue 12 Jun 2018 08:15
by Shalex
Thank you for letting us know.