title: Connection to SQL Server Works Sometimes
body: <p>An ADO.Net application is only sometimes able to connect to another server on the local network.  It seems random whether a given connection attempt succeeds or fails.  The connection is using a connection string in the form:</p>
  
  <blockquote>
    <p>Server=THESERVER\TheInstance;Database=TheDatabase;User Id=TheUser; Password=ThePassword;</p>
  </blockquote>
  
  <p>the error returned is:</p>
  
  <blockquote>
    <p>Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.<br>
    This could be because the pre-login handshake failed or the server was unable to respond back in time.<br>
    The duration spent while attempting to connect to this server was - [Pre-Login] initialization=42030; handshake=0; </p>
  </blockquote>
  
  <p>The .NET application is a small test app that executes the following code:</p>
  
  <pre><code>using (SqlConnection conn = new SqlConnection(cs))
  using (SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM TheTable", conn))
  {
      conn.Open();
      int rowCount = (int)cmd.ExecuteScalar();
  }
  </code></pre>
  
  <p><em>TheTable</em> is small, just 78 rows.</p>
  
  <p>However, on the <strong>same machine</strong> where the .NET application receives this error, I am able to connect to THESERVER using SSMS and the User Id/Password named in the connection string.</p>
  
  <p>Why might the connection fail from an ADO.Net app, but succeed with identical credentials from SSMS?</p>