【发布时间】:2018-06-05 08:21:35
【问题描述】:
在我们的 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 一起用于 Postgresql 数据库
知道为什么/何时发生此异常吗?
【问题讨论】:
-
我们使用 Devart 的库,它们通常非常可靠。显然,你的情况有些不妙。您的连接字符串是什么样的?创建数据库上下文的代码是什么样的?
-
连接字符串是:User Id=******;Password=******;Host=myHost;Database=myDb;Persist Security Info=True;Initial Schema=myInitialSchema ;Port=5432;Unicode=True 他构造的 dbContext 是:public MyContext(string nameOrConnectionString) { .... }
-
1.请向我们发送一个工作项目(尽可能简单)并指定重现错误应遵循的确切步骤:devart.com/company/contactform.html。 2. 告诉我们等待错误发生的大致时间。
标签: c# postgresql transactions entity-framework-6 devart