3

这个异常发生在这里:

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

堆栈跟踪:

[SqlException(0x80131904):不允许新事务,因为会话中还有其他线程在运行。] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +1753986 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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 stateOjbjHandler, TdsParser , 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[] 缓冲区, TransactionManagerRequestType 请求, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction 事务,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(IsolationLevelisolationLevel) +60 System.Data。Common.DbConnection.BeginTransaction(IsolationLevel isolationLevel) +10 System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel) +83

为什么会这样?

4

1 回答 1

2

我需要更多信息,因为我现在想要的是您的应用程序 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();
        }
    }
于 2013-05-23T12:21:53.343 回答