title: ASP.NET Core SQL Connection TImeout
body: <p>I've been working on upgrading an ASP.NET 5 RC1 app to ASP.NET Core 1. I have successfully upgraded it by replacing packages (AspNet to AspNetCore) and changing from EF7 to EF Core (Microsoft.Data.Entity to Microsoft.EntityFrameworkCore).</p>
  
  <p>The issue I'm having is an intermittent SqlException for Connection Timeout Expired.</p>
  
  <p>Here is the complete exception:  </p>
  
  <pre><code>System.Data.SqlClient.SqlException occurred.  
  Class=11 ErrorCode=-2146232060 HResult=-2146232060 LineNumber=0  
  **Message=Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=924; handshake=6;**   
    Number=-2   
    Procedure=""  
    Server=(localdb)\mssqllocaldb  
    Source=.Net SqlClient Data Provider  
    State=0  
    StackTrace:  
         at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)  
  </code></pre>
  
  <p>I have tried increasing the command timeout like so:</p>
  
  <pre><code>public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options)
  {
      this.Database.SetCommandTimeout(120);
  }
  </code></pre>
  
  <p>The exception is thrown on this line, but when I comment it out it will happen elsewhere which leads me to believe it happens the first time the database is accessed.</p>
  
  <pre><code>app.ApplicationServices.GetService&lt;ApplicationDbContext&gt;().Database.Migrate();
  </code></pre>