Skip to content

Conversation

benrr101
Copy link
Contributor

@benrr101 benrr101 commented Jun 4, 2025

Description

If I did all of this work in a single PR, I think it would be far too difficult to review. And to be honest, I'm not entirely sure how far down this rabbit hole goes. So, let's start with this and go from there.

While I was working on merging the SMI classes from netfx, I discovered that there was a lot of code that was marked "obsolete" or wasn't being used. This was generally the Context Connection. While I'm not entirely sure what it was supposed to do, there were large swaths of code that would change behavior if the connection was a context connection. However, it all hinged on a property in SqlConnectionString being true - but the property always returns false. So, once I delete that property, large chunks of code become broken. Going through those chunks of code, I see that entire methods and classes can be safely removed since they are no longer being used or doing anything functional.

This PR is structured to follow this thread. Each commit is self-contained and self-explanatory. I delete a chunk of code and anything that becomes unused, I mark with a @TODO. The subsequent commit deletes the code marked with a @TODO. The PR stops when the next batch of deletions start breaking the build.

Issues

N/A

Testing

CI testing should validate that behavior continues as expected. Though theoretically we're just deleting code paths that were never being exercised.

@benrr101 benrr101 added this to the 6.1.0 milestone Jun 4, 2025
@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 23:41
@benrr101 benrr101 added the Code Health 💊 Issues/PRs that are targeted to source code quality improvements. label Jun 4, 2025
@benrr101 benrr101 requested a review from a team as a code owner June 4, 2025 23:41
Copy link
Contributor

@Copilot 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 removes dead code paths tied to the always-false ContextConnection flag and cleans up related SMI/server-side classes and connection logic.

  • Deleted the ContextConnection property and all context-connection-specific branches
  • Refactored SqlConnectionFactory to simplify connection creation and pool options
  • Marked numerous obsolete SMI classes/methods (SmiRequestExecutor, SmiEventStream, SmiContext, etc.) for removal

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
SqlConnectionString.cs Removed always-false ContextConnection property
SmiRequestExecutor.netfx.cs Flagged unused methods with @TODO
SmiEventStream.netfx.cs Added @TODO to confirm usage
SmiContext.netfx.cs Added @TODO to identify unused abstractions
SqlInternalConnectionTds.cs Removed obsolete ContextConnection assertion
SqlInternalConnectionSmi.cs Marked constructors and methods for deletion
SqlDataReaderSmi.cs Flagged unused constructor with @TODO
SqlConnectionFactory.cs Simplified CreateConnection & pool options logic
SqlConnection.cs Removed context-connection properties and checks
SqlCommand.cs Eliminated context-connection SMI execution paths
SqlBulkCopy.cs Removed context-connection guard in validation
Comments suppressed due to low confidence (4)

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs:40

  • Refactoring of pool group options logic should be accompanied by unit tests to ensure pooling behavior remains correct across all edge cases.
override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions(DbConnectionOptions connectionOptions)

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs:1326

  • [nitpick] The context-connection guard is marked for deletion; remove this unused block to streamline the method.
// @TODO: No longer used -- delete!

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs:140

  • [nitpick] Passing a null literal for the nullable setEnlistValue parameter can be confusing; consider using a named boolean or introducing an explicit overload to make the intent clearer.
setEnlistValue: null); // Do not modify the enlist value

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs:143

  • The updated constructor invocation uses string.Empty and null for the password parameters, whereas previously the credential was passed through. Verify that this change preserves the intended authentication behavior.
return new SqlInternalConnectionTds(

@edwardneal
Copy link
Contributor

Great! As a rule of thumb, the context connection removal will eventually result in the removal of almost every file containing "Smi" in the name, and will leave a few of the netfx-specific files unused. It casts a very long shadow, and I think this PR handles the first 10-15%.

Once this is merged I'll update #2996 which should handle a few more parts of the codebase.

@cheenamalhotra cheenamalhotra modified the milestones: 6.1.0, 6.1-preview2 Jun 10, 2025
@cheenamalhotra cheenamalhotra requested a review from a team June 10, 2025 18:08
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 74.62687% with 17 lines in your changes missing coverage. Please review.

Project coverage is 68.24%. Comparing base (01f85bf) to head (31f1b2a).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...c/Microsoft/Data/SqlClient/SqlConnectionFactory.cs 67.39% 15 Missing ⚠️
...t/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs 85.71% 1 Missing ⚠️
...etfx/src/Microsoft/Data/SqlClient/SqlConnection.cs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3393       +/-   ##
===========================================
- Coverage   92.58%   68.24%   -24.34%     
===========================================
  Files           6      300      +294     
  Lines         310    65412    +65102     
===========================================
+ Hits          287    44639    +44352     
- Misses         23    20773    +20750     
Flag Coverage Δ
addons 92.58% <ø> (ø)
netcore 72.42% <ø> (?)
netfx 66.98% <74.62%> (?)

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.

@benrr101 benrr101 merged commit 7c5bd05 into main Jun 11, 2025
251 checks passed
@benrr101 benrr101 deleted the dev/russellben/cleanup/smi-dead-code branch June 11, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Health 💊 Issues/PRs that are targeted to source code quality improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants