这个例外发生在这里:
public void updateAccount(CommonLayer.Account account)
{
Entity.SaveChanges();
}
堆栈追踪:
[SqlException(0x80131904):不允许新事务,因为会话中还有其他线程在运行。 System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action
1 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的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,布尔&安培; 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
为什么会这样?
答案 0 :(得分:2)
我需要更多信息,因为我现在想要的是应用程序网络或桌面。如果您想使用 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();
}
}