gpt4 book ai didi

entity-framework - 实体异常: An error occurred while starting a transaction on the provider connection. 详情见内部异常

转载 作者:行者123 更新时间:2023-12-04 08:33:52 24 4
gpt4 key购买 nike

这个异常发生在这里:

public void updateAccount(CommonLayer.Account account)
{
Entity.SaveChanges();
}

堆栈跟踪:

[SqlException (0x80131904): New transaction is not allowed because there are other threads running in the session.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +1753986
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) +5296058 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69 System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) +796 System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) +395 System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) +137 System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName) +230 System.Data.SqlClient.SqlInternalConnection.BeginTransaction(IsolationLevel iso) +12 System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel) +60 System.Data.Common.DbConnection.BeginTransaction(IsolationLevel isolationLevel) +10 System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel) +83

为什么会这样?

最佳答案

我需要更多信息,因为我现在想了解您的应用程序 Web 或桌面。如果你想使用 EDM 你应该使用 using() 代码块。例如:

 public void SaveUser(User oldUser)
{
using (MyEntity myEntity= new MyEntity ())
{
var user = myEntity.Users.Where(u => u.UserId == oldUser.UserId).Single();
user.UserName = oldUser.UserName;
// and other changes
myEntity.SaveChanges();
}
}

关于entity-framework - 实体异常: An error occurred while starting a transaction on the provider connection. 详情见内部异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16712088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com