title: Automatic failover with SQL mirroring and connection strings
body: <p>I have 3 servers set up for SQL mirroring and automatic failover using a witness server. This works as expected. </p>
  
  <p>Now my application that connects to the database, seems to have a problem when a failover occurs - I need to manually intervene and change connection strings for it to connect again.
  The best solution I've found so far involves using <code>Failover Partner</code> parameter of the connection string, however it's neither intuitive nor complete: <code>Data Source="Mirror";Failover Partner="Principal"</code> <a href="http://blogs.msdn.com/b/spike/archive/2010/12/08/clarification-on-the-failover-partner-in-the-connectionstring-in-database-mirror-setup.aspx" rel="nofollow">found here</a>. </p>
  
  <p>From the example in the blog above (scenario #3) when the first failover occurs, and principal (failover partner) is unavailable, data source is used instead (which is the new principal). If it fails again (and I only tried within a limited period), it then comes up with an error message. This happens because the connection string is cached, so until this is refreshed, it will keep coming out with an error (it seems connection string refreshes ~5 mins after it encounters an error). If after failover I swap data source and failover partner, I will have one more silent failover again.</p>
  
  <p>Is there a way to achieve fully automatic failover for applications that use mirroring databases too (without ever seeing the error)?</p>
  
  <p>I can see potential workarounds using custom scripts that would poll currently active database node name and adjust connection string accordingly, however it seems like an overkill at the moment.</p>