C#C
C#3y ago
Natty

Multiple Users Concurrency Issue? EF6

It's a backend API with EF6 and frontend React/js coupled together (can't run the API separately). When multiple users try to upload a file at the same time, or run the main loop to perform calculations, the app crashes. The error message from the log is:
System.InvalidOperationException: Unexpected connection state. When using a wrapping provider ensure that the StateChange event is implemented on the wrapped DbConnection.

There was also a duplicate key error, but that must stem from the concurrency issues we're seeing.

The site works as intended even if users upload and run the main loop seconds apart, just not at the same time.

Can anyone pinpoint what this error actually means and the resolution? I've spent several hours reading, and it seems like it comes down to improper db context usage, but we instantiate a db context whenever we need it. I found an article that says this (see attached). I think we're doing that, but I don't know how to confirm.
image.png
Was this page helpful?