Random Errors Occur Using a DbContext Request

I experience random errors (several per day) in my mvc + ef + single application at a higher load (10 + request per second):

  • Connection was not closed / Current connection status is being connected
  • deadlocks in Count requests (no explicit transaction)
  • An item with the same key has already been added. in System.Data.Entity.DbContext.SetTEntity when DbContext is resolved
  • The remote host has closed the connection. Error Code: 0x80070057
  • There is already an open DataReader associated with this Command, which should be closed first. - I turned on MARS to get rid of this (although I believe that it should work correctly without MARS, there are no nested queries), which may cause another random error:
  • The server will disconnect the connection because the client driver has sent several requests while the session is in single-user mode.

I use this implementation of PerRequestLifetimeManager and have tried Unity.Mvc3 too without any difference.

There are some clues that the DbContext is not being deleted correctly. I am not sure that the cause of the problems is request-by-request, because this seems to be common practice .

+5
source share
1 answer

, DbContext , Rashid PerRequestLifetimeManager . Unity.Mvc3, , , , , .

, , .

SELECT ... FROM X JOIN Y ... JOIN Z ...

BEGIN TRAN
UPDATE Z ...
UPDATE Y ...
COMMIT TRAN

SELECT Y Z, TRAN Z Y

+3

All Articles