title: Web API - How to dispose an SQL connection correctly?
body: <p>I have a simple Web API controller:  </p>
  
  <pre><code>public class CarsController : ApiController
  {        
      public SqlConnection Db { get; set; }
  
      public CarsController()
      {            
          Db = new SqlConnection("XXX");
      }
  
      public async Task&lt;IEnumerable&lt;Car&gt;&gt; GetAll()
      {
          //Fetch cars from DB...            
      }
  
      protected override void Dispose(bool disposing)
      {
          if (disposing)
              Db.Dispose();
  
          base.Dispose(disposing);
      }
  }
  </code></pre>
  
  <p>I put the dispose code in Dipose() override because I want to <strong>write it once</strong>.</p>
  
  <ul>
  <li><p>Can I be sure the dispose code will be called in any situation? (Exceptions for
  example).</p></li>
  <li><p>Can I be sure that the controller will be disposed <strong>right after</strong> the
  call to the action is finished, freeing up resources to upcoming
  calls.</p></li>
  <li>If not, is there a more robust/correct way of doing this?</li>
  </ul>