-
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
new transaction is not allowed because there are other threads running in the session #10282
Comments
@supernarwen Can you post the full stack trace as well? How is |
Here is the full stack trace of the error.
Here is how I have registered my
Is it because I have not implemented And here is how my repositories are injected in DI. I am using
|
@supernarwen It's certainly the case that you need to dispose the DbContext properly. Beyond that, the context is not thread safe, nor are the underlying ADO.NET objects like DbConnection. Can you check that you don't have multiple threads accessing these thing concurrently? If after that you're still seeing an issue, then please post a complete code listing or project that reproduces that issue. |
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it. BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions. |
Hi, Regards |
@luigi68 Please file a new issue including a runnable project/solution or complete code listing that demonstrates the behavior you are seeing. |
I have the same problem after upgrading to EF Core 2.1, at least for now in two different places in the code, the same code was running with no problems before upgrade from 2.0 The issue seems to be related to union, after changing the code as below the error disappeared. This code failed
This code succeeded
But now there is an extra database request! I opened a new issue in thread #12549 |
Hi. I had the same issue and fixed the problem as per shaher's solution. i.e. two separate reads then union the result. |
This exception is due to Entity Framework creating an implicit transaction during the SaveChanges() call. Invoking C# SaveChanges() method begins a transaction which automatically rolls back all changes persisted to the database if an exception occurs before iteration completes; otherwise the transaction commits . The best way to work around the error is to use a different pattern (i.e., not saving while in the midst of reading) or by explicitly declaring a transaction. |
I am getting this error even though I am using asynchronous methods.
Here is the code where I am calling the method. I am getting error when I am trying to save
Resource
entity.Here is the how I have
SaveAsync()
methodSo, what happens is the error doesn't occur on record for first. But It occurs in next time when we save the new record.
Here is the screenshot of the stack trace.
http://prntscr.com/ha8fwx
Further technical details
EF Core version: 2.0
Database Provider: (Microsoft.EntityFrameworkCore.SqlServer)
Operating system:
IDE: (e.g. Visual Studio 2017)
The text was updated successfully, but these errors were encountered: