• The requested operation cannot be completed because the connection has been broken


    具体报错

    The requested operation cannot be completed because the connection has been broken. -- xxxForyyy->Index at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
    at System.Data.SqlClient.SqlDelegatedTransaction.Initialize()
    at System.Transactions.TransactionStatePSPEOperation.PSPEInitialize(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType)
    at System.Transactions.TransactionStateActive.EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction, Guid promoterType)
    at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Guid promoterType)
    at System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification)
    at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
    at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
    at System.Data.SqlClient.SqlInternalConnection.EnlistTransaction(Transaction transaction)
    at System.Data.SqlClient.SqlConnection.EnlistTransaction(Transaction transaction)
    at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<EnlistTransaction>b__30(DbConnection t, EnlistTransactionInterceptionContext c)
    at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
    at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.EnlistTransaction(DbConnection connection, EnlistTransactionInterceptionContext interceptionContext)
    at System.Data.Entity.Core.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction)

    错误:正在创建模型,此时不可使用上下文。如果在 OnModelCreating 方法内使用上下文或如果多个线程同时访问同一上下文实例,可能引发此异常。请注意不保证 DbContext 的实例成员和相关类是线程安全的。

    -------------------------

    原因可能是并发多线程调用DbContext问题,可以将报错点(Action,AttributeFilter)中的 DbContext 调用换成原生的SqlConnection 试下。

  • 相关阅读:
    delphi的dbgrid控件点击title排序
    在 Delphi 中使用微软全文翻译的小例子
    Google的搜索API的Delphi封装
    Delphi 自动检测U盘插入、拔出及获取U盘盘符!
    ERP开发准备
    Delphi中TStringList类常用属性方法详解
    JavaScript prototype详解
    TestNG 自动化测试入门教程--典型示例
    ucloud中的udisk错误“Read-only file system”修复指南
    websocket(二)--简单实现网页版群聊
  • 原文地址:https://www.cnblogs.com/runliuv/p/12915714.html
Copyright © 2020-2023  润新知