Skip to content

Conversation

@edwardneal
Copy link
Contributor

Description

This backports 66a67bc from #3575 to 6.1.

It's possible to start an application with the M.D.S EventSource already enabled, even before the static constructor for SqlClientEventSource has run. In this situation, the constructor for Log will run OnEventCommand with an enablement command before it finishes executing. This enablement tries to call Metrics.EnableEventCounters, but this hasn't been initialized yet - it relies on the SqlClientEventSource instance.

To break this cycle, we record the desired startup state of the metrics in this case, and pass it to the SqlClientMetrics constructor.

Issues

Fixes #3711.

Testing

The timing makes this difficult to test. In the end, I built a test application locally, referenced 6.1.2 and ran

dotnet counters monitor --counters Microsoft.Data.SqlClient.EventSource -- SqlClientTimeQuery.exe

This allowed me to reproduce the problem: the counters appear in 6.0, don't appear in 6.1.2, appear again in 7.0-preview2 and now also appear in my local build.

Could someone run CI please? @empowerRob you should be able to verify with the nupkg build artifact.

@edwardneal edwardneal requested a review from a team as a code owner October 24, 2025 16:34
@cheenamalhotra cheenamalhotra added this to the 6.1.3 milestone Oct 24, 2025
@cheenamalhotra
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.32%. Comparing base (7a7b54e) to head (9bb2e60).
⚠️ Report is 17 commits behind head on release/6.1.

Files with missing lines Patch % Lines
...oft/Data/SqlClient/Diagnostics/SqlClientMetrics.cs 66.66% 1 Missing ⚠️
...c/Microsoft/Data/SqlClient/SqlClientEventSource.cs 80.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7a7b54e) and HEAD (9bb2e60). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (7a7b54e) HEAD (9bb2e60)
addons 1 0
Additional details and impacted files
@@               Coverage Diff                @@
##           release/6.1    #3718       +/-   ##
================================================
- Coverage        69.69%   59.32%   -10.37%     
================================================
  Files              281      273        -8     
  Lines            62413    61434      -979     
================================================
- Hits             43500    36448     -7052     
- Misses           18913    24986     +6073     
Flag Coverage Δ
addons ?
netcore 63.84% <75.00%> (-8.92%) ⬇️
netfx 60.97% <100.00%> (-8.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cheenamalhotra cheenamalhotra merged commit b1bf339 into dotnet:release/6.1 Oct 28, 2025
236 checks passed
@edwardneal edwardneal deleted the port/pr-3575/release-6.1 branch October 28, 2025 16:03
This was referenced Nov 14, 2025
This was referenced Nov 18, 2025
github-merge-queue bot pushed a commit to DFE-Digital/teaching-record-system that referenced this pull request Nov 26, 2025
Updated [Microsoft.Data.SqlClient](https://github.com/dotnet/sqlclient)
from 6.1.2 to 6.1.3.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Data.SqlClient's
releases](https://github.com/dotnet/sqlclient/releases)._

## 6.1.3

This update includes the following changes since the
[6.1.2](https://github.com/dotnet/SqlClient/blob/main/release-notes/6.1/6.1.2.md)
release:

### Added

#### App Context Switch for Ignoring Server-Provided Failover Partner

*What Changed:*

- A new app context switch
`Switch.Microsoft.Data.SqlClient.IgnoreServerProvidedFailoverPartner`
was introduced to let the client ignore server-provided failover partner
info in Basic Availability Groups (BAGs). When the switch is enabled,
only the failover partner specified in the connection string is used;
server-supplied partner values are skipped. This context switch was
introduced in PR
[#​3702](dotnet/SqlClient#3702).

*Who Benefits:*

- Applications connecting to SQL Server BAGs using TCP and custom ports,
especially where the server's provided partner name lacks the protocol,
host, or port. This avoids connection failures when the server-provided
partner is incompatible or incomplete.
- Teams who manage availability groups and rely on client-side control
of failover behavior in heterogeneous networking environments.

*Impact:*

- If your environment might be affected (i.e., you operate a BAG with
custom ports, or have experienced failures after failover), you can
enable the new switch in your application:

```c#
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.IgnoreServerProvidedFailoverPartner", true);
```

- Then, ensure your connection string includes your preferred failover
partner (with correct `tcp:host,port`) so that the client uses that
instead of the server's suggestion.
- Without enabling this, by default, the client continues to prefer the
server-provided partner, maintaining backwards compatibility.

### Fixed

- Fixed an issue to ensure reliable metrics initialization during
startup, preventing missed telemetry when EventSource is enabled early.
([#​3718](dotnet/SqlClient#3718))

## Target Platform Support

- .NET Framework 4.6.2+ (Windows ARM64, Windows x86, Windows x64)
- .NET 8.0+ (Windows x86, Windows x64, Windows ARM64, Windows ARM,
Linux, macOS)

### Dependencies

#### .NET Framework 4.6.2+

- Azure.Core 1.47.1
- Azure.Identity 1.14.2
- Microsoft.Bcl.Cryptography 8.0.0
- Microsoft.Data.SqlClient.SNI 6.0.2
- Microsoft.Extensions.Caching.Memory 8.0.1
- Microsoft.IdentityModel.JsonWebTokens 7.7.1
- Microsoft.IdentityModel.Protocols.OpenIdConnect 7.7.1
- System.Buffers 4.5.1
- System.Data.Common 4.3.0
- System.Security.Cryptography.Pkcs 8.0.1
- System.Text.Encodings.Web 8.0.0
 ... (truncated)

Commits viewable in [compare
view](dotnet/SqlClient@v6.1.2...v6.1.3).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Data.SqlClient&package-manager=nuget&previous-version=6.1.2&new-version=6.1.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants