There is already an open DataReader associated with this Command which must be closed first.
See original GitHub issueHi, I am using ASP.NET 5.0 and Linq2Db 3.2.1 for my API. I use SQL Server I am following this guide https://linq2db.github.io/articles/get-started/asp-dotnet-core/index.html I also use services.AddLinqToDbContext to register my DataConnection with the ServiceLifetime is Scoped.
And I got this error when I send 2 requests in the same time. “There is already an open DataReader associated with this Command which must be closed first.”
I think change the ServiceLifetime to Transient is not the good practices. Do you have any ways else or guide doc to solve this issue? Thank you!
For more detail:
fail: LinqToDB.Data.DataConnection[0]
Error
Exception: System.InvalidOperationException
Message : There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__126_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at LinqToDB.Data.DataConnection.ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
There is already an open DataReader associated with this ...
There is already an open DataReader associated with this Command which must be closed first. Update: stack trace added:
Read more >Why do I get the error message 'There is already an open ...
Why do I get the error message 'There is already an open DataReader associated with this Connection which must be closed first.' ......
Read more >There is already an open DataReader associated with this ...
Close the DataReader & then SqlConnection, if there is an exception is not getting closed. best practices to write this code in try...
Read more >There is already an open DataReader associated with this ...
With SQL-Server: Exception: There is already an open DataReader associated with this Command which must be closed first. Code: using ( ...
Read more >Script Task: There is already an open DataReader ...
Script Task : There is already an open DataReader associated with this Command which must be closed first. ' A Microsoft platform for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As I know each request creates scope which equals to creating new DataConnection. Probably problem in you controller, for example missed
await
, or you have written something like this:yep, but you need to wait for #2728 to make it work with linq2db