Postgresql Devart EF:底层提供程序在Open上失败

时间:2018-06-05 08:21:35

标签: c# postgresql transactions entity-framework-6 devart

我在Postgre Db上使用实体框架执行简单的读取查询时遇到此异常, 在抛出此异常的代码中,我不使用事务 代码不会系统地但随机地失败

这是堆栈跟踪:

{
  "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
}

在Db中启用了事务, 我设置了max_prepared_transactions = max_connections =100

我使用Devart提供程序和EF for Postgresql数据库

知道为什么/何时发生这种异常?

1 个答案:

答案 0 :(得分:1)

通过在创建transactionscope时设置TransactionScopeAsyncFlowOption.Enabled来解决

问题

https://particular.net/blog/transactionscope-and-async-await-be-one-with-the-flow

相关问题