Improved MultiSubnet Listener Behavior With Newly Released SQL Client Provider in .NET 4.6.1

Published Jan 15 2019 04:48 PM 1,401 Views
Microsoft
First published on MSDN on Dec 01, 2015

SQL Client Provider Behavior With MultiSubnet Listener Results in Connection Timeouts


The first experience trying to connect to an availability group listener defined with multiple IP addresses, may be intermittent connection timeouts.

The default behavior of the SQL client libraries is to try all IP addresses returned by the DNS lookup - one after another (serially) until the all of the IP addresses have been exhausted and either a connection is made, or a connection timeout threshold has been reached. This can be problematic, because depending upon DNS configurations, the “correct” or “online” IP address may not be the first IP address returned. The default timeout for a TCP connection attempt is 21 seconds and if the first IP address attempted is not online, it will wait 21 seconds before attempting the next IP address. For each subsequent IP address, it will again have to wait 21 seconds before moving to the next IP address until the connection attempt times out or it establishes a connection to an IP address that responds.

For more information on the symptoms associated with the SQL Client’s legacy default behavior (MultiSubnetFailover=FALSE) see our other AlwaysOnPro article:
Connection Timeouts in Multi-subnet Availability Group

Improved SQL Client Provider Defaults to MultiSubnetFailover=TRUE


That changes with the updated SQL Client provider shipping in .NET 4.6.1. Now SQL Client Provider's default behavior is to retrieve all IP addresses up front and attempt to connect to them all in parallel. This should result in the successful connection to the online IP addresss and is the optimal way to reconnect to an availability group in the event of failover.





The following article describes the improvement in more detail and a download link to the updated .NET package:
.NET Framework 4.6.1 is now available!

Improve MultisubnetFailover connection behavior for AlwaysOn

The SqlClient now automatically provides faster connection to AlwaysOn Availability Group that was introduced in SQL Server 2012. It transparently detects whether your application is connecting to an AlwaysOn availability group (AG) on different subnet and quickly discovers the current active server and provides connection to the server.

Prior to this release, an application has to set connection string to include “MultisubnetFailover=true” to indicate that it is connecting to AlwaysOn Availability Group. Without turning on the connection keyword, an application might experience a timeout while connecting to AlwaysOn Availability Group.

With this feature an application does not need to set MultisubnetFailover to true anymore. For more information about SqlClient support for AlwaysOn Availability Groups, see SqlClient Support for High Availability, Disaster Recovery .

For more information on SQL Client Provider support for High Availability and specific support for the MultiSubnetFailover connection string parameter see:
SqlClient Support for High Availability, Disaster Recovery
%3CLINGO-SUB%20id%3D%22lingo-sub-318664%22%20slang%3D%22en-US%22%3EImproved%20MultiSubnet%20Listener%20Behavior%20With%20Newly%20Released%20SQL%20Client%20Provider%20in%20.NET%204.6.1%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318664%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Dec%2001%2C%202015%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1702883319%22%20id%3D%22toc-hId-1763068890%22%3ESQL%20Client%20Provider%20Behavior%20With%20MultiSubnet%20Listener%20Results%20in%20Connection%20Timeouts%3C%2FH2%3E%3CBR%20%2F%3E%20The%20first%20experience%20trying%20to%20connect%20to%20an%20availability%20group%20listener%20defined%20with%20multiple%20IP%20addresses%2C%20may%20be%20intermittent%20connection%20timeouts.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20default%20behavior%20of%20the%20SQL%20client%20libraries%20is%20to%20try%20all%20IP%20addresses%20returned%20by%20the%20DNS%20lookup%20-%20one%20after%20another%20(serially)%20until%20the%20all%20of%20the%20IP%20addresses%20have%20been%20exhausted%20and%20either%20a%20connection%20is%20made%2C%20or%20a%20connection%20timeout%20threshold%20has%20been%20reached.%20This%20can%20be%20problematic%2C%20because%20depending%20upon%20DNS%20configurations%2C%20the%20%E2%80%9Ccorrect%E2%80%9D%20or%20%E2%80%9Conline%E2%80%9D%20IP%20address%20may%20not%20be%20the%20first%20IP%20address%20returned.%20The%20default%20timeout%20for%20a%20TCP%20connection%20attempt%20is%2021%20seconds%20and%20if%20the%20first%20IP%20address%20attempted%20is%20not%20online%2C%20it%20will%20wait%2021%20seconds%20before%20attempting%20the%20next%20IP%20address.%20For%20each%20subsequent%20IP%20address%2C%20it%20will%20again%20have%20to%20wait%2021%20seconds%20before%20moving%20to%20the%20next%20IP%20address%20until%20the%20connection%20attempt%20times%20out%20or%20it%20establishes%20a%20connection%20to%20an%20IP%20address%20that%20responds.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EFor%20more%20information%20on%20the%20symptoms%20associated%20with%20the%20SQL%20Client%E2%80%99s%20legacy%20default%20behavior%20%3C%2FSTRONG%3E%20(MultiSubnetFailover%3DFALSE)%20see%20our%20other%20AlwaysOnPro%20article%3A%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Falwaysonpro%2Farchive%2F2014%2F06%2F03%2Fconnection-timeouts-in-multi-subnet-availability-group.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Connection%20Timeouts%20in%20Multi-subnet%20Availability%20Group%20%3C%2FA%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--849273642%22%20id%3D%22toc-hId--789088071%22%3EImproved%20SQL%20Client%20Provider%20Defaults%20to%20MultiSubnetFailover%3DTRUE%3C%2FH2%3E%3CBR%20%2F%3E%20That%20changes%20with%20the%20updated%20SQL%20Client%20provider%20shipping%20in%20.NET%204.6.1.%20Now%20SQL%20Client%20Provider's%20default%20behavior%20is%20to%20retrieve%20all%20IP%20addresses%20up%20front%20and%20attempt%20to%20connect%20to%20them%20all%20in%20parallel.%20This%20should%20result%20in%20the%20successful%20connection%20to%20the%20online%20IP%20addresss%20and%20is%20the%20optimal%20way%20to%20reconnect%20to%20an%20availability%20group%20in%20the%20event%20of%20failover.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68374iE6FBBAD7D91FB798%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20following%20article%20describes%20the%20improvement%20in%20more%20detail%20and%20a%20download%20link%20to%20the%20updated%20.NET%20package%3A%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fdotnet%2Farchive%2F2015%2F11%2F30%2Fnet-framework-4-6-1-is-now-available.aspx%22%20title%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fdotnet%2Farchive%2F2015%2F11%2F30%2Fnet-framework-4-6-1-is-now-available.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20.NET%20Framework%204.6.1%20is%20now%20available!%20%3C%2FA%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CSTRONG%3E%3CEM%3EImprove%20MultisubnetFailover%20connection%20behavior%20for%20AlwaysOn%20%3C%2FEM%3E%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20The%20%3C%2FEM%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fsystem.data.sqlclient(v%3Dvs.110).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20%3CEM%3E%20SqlClient%20%3C%2FEM%3E%20%3C%2FA%3E%20%3CEM%3E%20now%20automatically%20provides%20faster%20connection%20to%20%3C%2FEM%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fhh510230.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20%3CEM%3E%20AlwaysOn%20Availability%20Group%20%3C%2FEM%3E%20%3C%2FA%3E%20%3CEM%3E%20that%20was%20introduced%20in%20SQL%20Server%202012.%20It%20transparently%20detects%20whether%20your%20application%20is%20connecting%20to%20an%20AlwaysOn%20availability%20group%20(AG)%20on%20different%20subnet%20and%20quickly%20discovers%20the%20current%20active%20server%20and%20provides%20connection%20to%20the%20server.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Prior%20to%20this%20release%2C%20an%20application%20has%20to%20set%20connection%20string%20to%20include%20%E2%80%9CMultisubnetFailover%3Dtrue%E2%80%9D%20to%20indicate%20that%20it%20is%20connecting%20to%20AlwaysOn%20Availability%20Group.%20Without%20turning%20on%20the%20connection%20keyword%2C%20an%20application%20might%20experience%20a%20timeout%20while%20connecting%20to%20AlwaysOn%20Availability%20Group.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20With%20this%20feature%20an%20application%20does%20not%20need%20to%20set%20MultisubnetFailover%20to%20true%20anymore.%20For%20more%20information%20about%20SqlClient%20support%20for%20AlwaysOn%20Availability%20Groups%2C%20see%20%3C%2FEM%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fhh205662(v%3Dvs.110).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20%3CEM%3E%20SqlClient%20Support%20for%20High%20Availability%2C%20Disaster%20Recovery%20%3C%2FEM%3E%20%3C%2FA%3E%20%3CEM%3E%20.%20%3C%2FEM%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%20%3CSTRONG%3EFor%20more%20information%20on%20SQL%20Client%20Provider%20support%20for%20High%20Availability%20%3C%2FSTRONG%3E%20and%20specific%20support%20for%20the%20MultiSubnetFailover%20connection%20string%20parameter%20see%3A%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fhh205662(v%3Dvs.100).aspx%22%20title%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fhh205662(v%3Dvs.100).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20SqlClient%20Support%20for%20High%20Availability%2C%20Disaster%20Recovery%20%3C%2FA%3E%3C%2FBLOCKQUOTE%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318664%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Dec%2001%2C%202015%20SQL%20Client%20Provider%20Behavior%20With%20MultiSubnet%20Listener%20Results%20in%20Connection%20TimeoutsThe%20first%20experience%20trying%20to%20connect%20to%20an%20availability%20group%20listener%20defined%20with%20multiple%20IP%20addresses%2C%20may%20be%20intermittent%20connection%20timeouts.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318664%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Econnectivity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHigh%20Availability%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 04:48 PM
Updated by: