Skip to content

Conversation

@apoorvdeshmukh
Copy link
Contributor

@apoorvdeshmukh apoorvdeshmukh commented Dec 11, 2025

Description

This PR introduces new app context switch Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault to set MultiSubnetFailover=true by default in connection string.

Usage

In application

AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault", true);

Or In config file runtimeconfig.json

{
  "configProperties": {
    "Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault": true
  }
}

Or in App.Config

<runtime>
  <AppContextSwitchOverrides value="Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault=true" />
</runtime>

Issues

AB#40809

Testing

Enhanced LocalAppContextSwitchesTest.cs to test new app context switch.
Added unit tests in SqlConnectionStringTest.cs

Guidelines

Please review the contribution guidelines before submitting a pull request:

@apoorvdeshmukh apoorvdeshmukh requested a review from a team as a code owner December 11, 2025 12:43
Copilot AI review requested due to automatic review settings December 11, 2025 12:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new app context switch Switch.Microsoft.Data.SqlClient.EnableMSFByDefaultInConnString that allows applications to change the default value of the MultiSubnetFailover connection string property from false to true. This enables parallel IP connection attempts by default in multi-subnet environments, which can improve connection times for Always On availability groups.

Key changes:

  • Implements the app context switch following established patterns in the codebase
  • Changes DbConnectionStringDefaults.MultiSubnetFailover from a const to a property that reads the switch value
  • Adds comprehensive unit tests covering various scenarios including explicit overrides and FailoverPartner validation
  • Properly integrates with the existing test infrastructure for app context switch testing

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs Adds the new app context switch constant, static field, and public property with XML documentation
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/ConnectionString/DbConnectionStringDefaults.cs Changes MultiSubnetFailover from const to property that reads from the app context switch
src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs Adds test helper infrastructure to manipulate and restore the switch state for testing
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs Adds comprehensive unit tests for the new switch behavior including edge cases
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs Updates default value assertion test to include the new switch

@paulmedynski paulmedynski self-assigned this Dec 11, 2025
@cheenamalhotra cheenamalhotra added the Hotfix Candidate 🚑 Issues/PRs that are candidate for backporting to earlier supported versions. label Dec 11, 2025
Copilot AI review requested due to automatic review settings December 11, 2025 18:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

@apoorvdeshmukh apoorvdeshmukh merged commit deb8c31 into main Dec 12, 2025
256 checks passed
@apoorvdeshmukh apoorvdeshmukh deleted the dev/ad/acs-msf branch December 12, 2025 10:01
apoorvdeshmukh added a commit that referenced this pull request Dec 15, 2025
apoorvdeshmukh added a commit that referenced this pull request Dec 15, 2025
apoorvdeshmukh added a commit that referenced this pull request Dec 15, 2025
apoorvdeshmukh added a commit that referenced this pull request Dec 16, 2025
…by default (#3851)

This commit introduces app context switch for setting
MultiSubnetFailover=true by default in connection
string when the app context switch is set to true.
The default value of the context switch is false.
apoorvdeshmukh added a commit that referenced this pull request Dec 16, 2025
… by default (#3852)

This commit introduces app context switch EnableMultiSubnetFailoverByDefault
to set MultiSubnetFailover=true in connection string by default when the app
context switch is set to true. The default value of this context switch is set to 
false.
@apoorvdeshmukh apoorvdeshmukh modified the milestone: 5.1.9 Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hotfix Candidate 🚑 Issues/PRs that are candidate for backporting to earlier supported versions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants