At Stack Exchange we need to support SQL Server AlwaysOn Availability Groups, 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 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. We're going to use Microsoft's native driver as the reference implementation for how connection attempts should be performed. See SQL Server Native Client Support for High Availability, Disaster Recovery.
At Stack Exchange we need to support SQL Server AlwaysOn Availability Groups, 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
fReadOnlyIntentbit. I found that Tedious had the wrong bits set for the variousTypeFlags. Fixing that allowed setting thefReadOnlyIntentbit and getting the properENVCHANGEtoken (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 theENVCHANGEtoken.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
REROUTINGstate for that. We're going to use Microsoft's native driver as the reference implementation for how connection attempts should be performed. See SQL Server Native Client Support for High Availability, Disaster Recovery.