DbContext Not Being Disposed Ef Core 1.1
See original GitHub issueSteps to reproduce
using (var ctx = new ReportingDbContext())
{
var result = await ctx.Companies.ToListAsync();
return View(result);
}
The issue
The connection to the database is not being disposed after the result is being returned to the view. After the view has finished rendering, the view result is complete and nothing makes requests to the controller.
Further technical details
EF Core version: 1.1.0 Operating system: Windows 10 Visual Studio version: 2015 Version 14.0.25422.01 Update 3
Other details about my project setup: I am using the following database Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright © Microsoft Corporation Express Edition (64-bit) on Windows 10 Home 6.3 <X64> (Build 14393: )
This was addressed in #6581 and patch was approved. I do not believe it was merged into the correct and put into the patch train.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
It seems that ef-core dbcontext using Dependency Injection ...
My team is working on converting legacy system from delphi to asp.net core. And in the course of test we found that dbcontext...
Read more >DbContext Lifetime, Configuration, and Initialization
It is very important to dispose the DbContext after use. This ensures both that any unmanaged resources are freed, and that any events...
Read more >Should we Dispose of a DBContext (Entity Framework)?
The general rule with disposing is that you dispose things you create and do not dispose things that are passed to you as...
Read more >c# - DbContext gets disposed in BackgroundService ...
The issue is caused by the fact that the outer scope created by _serviceScopeFactory.CreateScope() is disposed after each using statement, whereas each ...
Read more >It seems that ef-core dbcontext using Dependency Injection is ...
It seems that ef-core dbcontext using Dependency Injection is not disposed · Create new DbContext dynamically when using ASP.Net Core dependency injection ...
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
@ajcvickers I was able to add Pooling=False in my connection string and prove your position that Activity Monitor is not an accurate method due to connection pooling. Thank you for very much for the your time and help. I will close this issue due to it being a matter of user education.
@euclid47 This is not an accurate way of determining that connections have been closed or disposed because the SQL Client ADO.NET provider is using connection pooling. This means that a connection can be closed and disposed in .NET without the underlying pipeline to the database being closed.