EF Core - System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed
<p>I'm running an ASP.NET Core 1.0 web app with Entity Framework Core. When the app has been running for a while (24 - 48 hours), the app starts crashing on every request to any endpoint or static resource throwing the error <code>System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed.</code> I can only recover from this by restarting the App Pool.</p>

<p>I am configuring Entity Framework like this:</p>

<p>Startup.cs</p>

<pre><code>public void ConfigureServices(IServiceCollection services)
{
        services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));   
}
</code></pre>

<p>I am loading data in the owin pipeline with an extension method like this like this:</p>

<p>Startup.cs</p>

<pre><code>app.LoadTenantData();
</code></pre>

<p>AppBuilderExtensions.cs:</p>

<pre><code>public static void LoadTenantData(this IApplicationBuilder app)
    {
        app.Use(async (context, next) =&gt;
        {
            var dbContext = app.ApplicationServices.GetService&lt;ApplicationDbContext&gt;();        
            var club = dbContext.Clubs.Single(c =&gt; c.Id == GetClubIdFromUrl(context));
            context.Items[PipelineConstants.ClubKey] = club;
            await next();
        });
    }
</code></pre>

<p>Since the error only occurs when the app has been running for a long time, it is hard to reproduce, but I'm assuming it has something to do with EF opening and closing connections incorrectly.</p>

<p>How can I go about to debug this? Am I using EF incorrectly? </p>