代码之家  ›  专栏  ›  技术社区  ›  Mouadh

PostgreSQL Devart EF:基础提供程序在打开时失败

  •  0
  • Mouadh  · 技术社区  · 8 年前

    我在postgre数据库上使用实体框架执行简单的读取查询时遇到了这个异常, 在抛出此异常的代码中,我不使用事务 代码不是系统性的失败,而是随机的

    这个堆栈跟踪:

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

    在数据库中,事务被启用, 我设定 max_prepared_transactions = max_connections =100

    我在postgresql数据库中使用带ef的devart provider

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Mouadh    8 年前

    通过设置解决问题 TransactionScopeAsyncFlowOption.Enabled 创建TransactionScope时

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