title: EF Core and big traffic leads to max pool size was reached error
body: <p>We're using ASP.NET Entity Framework Core for querying our MSSQL database in our Web API app. Sometimes when we have big traffic, querying to DB ends with this error:</p>
  
  <blockquote>
    <p>Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.</p>
  </blockquote>
  
  <p>I wonder if our pattern of using <code>DbContext</code> and querying is correct or if I am missing some using/dispose pattern and error is caused by some memory leak (after some research I read then I should not use using because the lifetime is managed by the framework). I am following <a href="https://docs.efproject.net/en/latest/miscellaneous/configuring-dbcontext.html#using-dbcontext-with-dependency-injection" rel="noreferrer">documentation</a>...</p>
  
  <p>My connectionString:</p>
  
  <pre><code>"myConnection": "Server=xxx;Database=xxx;user id=xxx;password=xxx;Max Pool Size=200;Timeout=200;"
  </code></pre>
  
  <p>My Startup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
      {
      .....
      // scoped context            
      services.AddDbContext&lt;MyDbContext&gt;(
              options =&gt; options.UseSqlServer(this.Configuration.GetConnectionString("myConnection")));
      }
  </code></pre>
  
  <p>then in controllers I used dbcontext by dependency injection:</p>
  
  <pre><code>public class MyController : Controller
     public MyController (MyDbContext context)
      {
          this.Context = context;            
      }
  
      public ActionResult Get(int id)
      {
          // querying
          return this.Context.tRealty.Where(x=&gt;x.id == id).FirstOrDefault();
      }
  </code></pre>
  
  <p>Should I use something like:</p>
  
  <pre><code>using (var context = this.Context)
          {
              return this.Context.tRealty.Where(x =&gt; x.id == id).FirstOrDefault();
          }
  </code></pre>
  
  <p>But I think that this is bad pattern when I am using dependency injection of <code>DbContext</code>.</p>