This exception happened here:
public void updateAccount(CommonLayer.Account account)
{
Entity.SaveChanges();
}
Stack Trace:
[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, 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 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
Why is this happening?
I needed more info because I want to now is you application web or desktop. If you want to use EDM you should to use using() code block. For example:
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();
}
}