-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"connection's current state is open" #3240
Comments
@endink DbContext is not thread-safe and interleaving query execution like this on the same instance is not supported. The error condition you are running into ("connection's current state is open") is possibly the most innocuous problem you may have if you do this. Any state maintained by the DbContext can as well be corrupted. DbContext has never been thread safe in any previous version of EF. In EF6 we added guards in the async APIs to throw a specific exception when they were used in this way. We should probably consider doing this again in EF7. On the other hand, I am not sure how the part about "pending model changes" is related. Does that go away if you serialize your async queries (e.g. awaiting each individual call to |
thanks, so i use "await" it works fine, "pending model changes" is a bug in my code, sorry . thanks again. |
When i use inject a dbcontext in a controller, and execute multi threaded query, like this:
Task t1 = query 1(ToArrayAsync());
Task t2 = query 2;
Task t3 = query 3;
Task.WhenAll(t1, t2, t3);
Often an error occurred:
A database operation failed while processing the request.
"connection's current state is open"
There are pending model changes for ApplicationDbContext
Scaffold a new migration for these changes and apply them to the database from the command line:
The text was updated successfully, but these errors were encountered: