question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DbContext Not Being Disposed Ef Core 1.1

See original GitHub issue

Steps 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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
euclid47commented, Dec 15, 2016

@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.

1reaction
ajcvickerscommented, Dec 14, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found