pekim/tedious — pull request #182 by rossipedia (2014-09-08 17:27:22+00:00)
Title: Support SQL Server Availability Groups

At Stack Exchange we need to support [SQL Server AlwaysOn Availability Groups][1], and bringing this support to Tedious would make it a much more viable solution for those in similar situations. There's definitely quite a few parts to getting the full feature-set implemented, so I'd like to keep this PR open as kind of a running discussion/integration during the implementation process.

The first set of changes involves the [`fReadOnlyIntent`](http://msdn.microsoft.com/en-us/library/dd304019.aspx) bit. I found that Tedious had the wrong bits set for the various `TypeFlags`. Fixing that allowed setting the `fReadOnlyIntent` bit and getting the proper `ENVCHANGE` token (type 20) back from SQL Server after logging in. After that it was a matter of fixing up the state machine to properly transition and reconnect to the server/port indicated in the `ENVCHANGE` token.

Hopefully (meaning I haven't tested this yet), this will have the added benefit of gracefully handling a manual fail-over as well.

The next step is to handle the situation where a DNS lookup for the SQL Server host name returns multiple IP addresses, which should be attempted in order until a connection is made. I'm pretty sure I'll be able to re-use the `REROUTING` state for that.

[1]: http://msdn.microsoft.com/en-us/library/ff877884.aspx