Skip to content

Driver does not return to gateway on connection timeouts #3528

Closed

Description

@mdaigle

Describe the bug

When a server instance goes down or comes under heavy load, it can begin timing out on prelogin requests. As long as these timeouts take less than the user-configured connection timeout, the driver will keep retrying until the connection timeout is reached. If the driver was routed to the server by a gateway or AOAG listener, these retries are against the routed location. The driver does not return to the gateway for fresh routing instructions.

Relates to #3527

To reproduce

To reliably reproduce, requires a custom server instance where arbitrary delays can be injected.

Set up a gateway or AOAG listener and route it to a custom sql server instance.

On the server, inject a delay of 10s on prelogin.

Connect to the server with the following options:
ConnectTimeout = 30
ConnectRetryInterval = 1

Observe that multiple connection attempts are made and that each attempt targets the server and does not return to the gateway.

Expected behavior

Upon encountering any connection error, the driver should return to the gateway or listener to be routed from scratch.

Further technical details

Microsoft.Data.SqlClient version: 5.1, 6.0, 6.1
.NET target: all targets
SQL Server version: any
Operating system: any

Activity

  1. added this to the 6.1.1 milestone on Jul 29, 2025
  2. added theissue type on Jul 29, 2025
  3. self-assigned this
    on Jul 29, 2025
  4. mdaigle commented on Aug 18, 2025

    @mdaigle
    ContributorAuthor

    TransparentNetworkIPResolution is defaulting to "True" for .NET Framework. This enables the "parallel" retry strategy optimized for servers with explicit failover partner configurations. When connecting to azure servers, the parallel strategy prevents us from returning to the gateway. Any customer who uses .NET Framework, connects to an azure sql database, and does not explicitly set TransparentNetworkIPResolution to false in their connection string or via app context switch can face this issue.

    Our documentation suggests that TNIR is disabled when connecting to an azure sql server or using certain auth modes, but this is not reflected in the code: https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring?view=sqlclient-dotnet-core-6.0

  5. mdaigle commented on Aug 18, 2025

    @mdaigle
    ContributorAuthor

    The TNIR default value is set as !LocalAppContextSwitches.DisableTnirByDefault
    That flag is off by default, resulting in TNIR = true

  6. cheenamalhotra commented on Aug 19, 2025

    @cheenamalhotra
    Member

    @saurabh500 for awareness: Any concerns from your perspective in fixing this behavior?

  7. moved this from To triage to Backlog in SqlClient Boardon Oct 8, 2025
  8. mdaigle commented on Oct 28, 2025

    @mdaigle
    ContributorAuthor

    Determined that this behavior was due to TNIR. Disabling TNIR gives the expected behavior.

  9. removed this from the 7.0.0-preview3 milestone on Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions