[英]Postgresql Devart EF : The underlying provider failed on Open
當我在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數據庫
不知道為什么/何時發生此異常?
通過在創建transactionscope時設置TransactionScopeAsyncFlowOption.Enabled
修復的問題
https://particular.net/blog/transactionscope-and-async-await-be-one-with-the-flow
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.