Error with transactions : The current TransactionScope is already complete.

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
mouadh
Posts: 3
Joined: Tue 05 Jun 2018 07:50

Error with transactions : The current TransactionScope is already complete.

Post by mouadh » Tue 05 Jun 2018 08:08

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

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Thu 07 Jun 2018 18:48

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.

mouadh
Posts: 3
Joined: Tue 05 Jun 2018 07:50

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

Post by mouadh » Fri 08 Jun 2018 13:41

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);

mouadh
Posts: 3
Joined: Tue 05 Jun 2018 07:50

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

Post by mouadh » Mon 11 Jun 2018 14:02

problem fixed by setting `TransactionScopeAsyncFlowOption.Enabled` when creating the transactionscope

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

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 12 Jun 2018 08:15

Thank you for letting us know.

Post Reply