Skip to content

Refactor TDS parser into focused namespaces and files - #4810

Open
benrr101 wants to merge 15 commits into
mainfrom
dev/russellben/tds-groups
Open

benrr101 wants to merge 15 commits into
mainfrom
dev/russellben/tds-groups

Conversation

@benrr101

@benrr101 benrr101 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Description

Refactors the TDS parser implementation into focused files and namespaces without changing its public API or intended behavior.

  • Splits helper types, enums, safe handles, parser state, and related classes out of the large legacy source files.
  • Moves parser implementation types under Microsoft.Data.SqlClient.Parser.
  • Groups login and token-related types under Parser.Login and Parser.Tokens.
  • Preserves file history through step-wise moves so reviewers can distinguish relocation from structural cleanup.
  • Updates internal references and affected tests for the new namespaces.

This is layer 1 of 3 in the TDS parser organization stack and targets main.

Issues

Supersedes closed PR #4675. No linked issue; this is an internal code-organization refactor.

Testing

Existing functional, manual, and unit test sources are updated to use the reorganized parser namespaces. No new test run was performed during PR submission.

Guidelines

@benrr101
benrr101 requested a review from a team as a code owner October 9, 2026 16:19
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:19
@benrr101
benrr101 added this pull request to stack #4813 October 9, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Several manual and stress-test reflection or stack-frame references still use the former parser namespaces and now fail or stop matching.

1 open finding
What changed in this PR

Reorganizes internal TDS parsing code into focused parser, login, token, and native-SNI namespaces without intentionally changing public behavior.

Changes:

  • Splits legacy parser helpers into dedicated files and namespaces.
  • Updates production and test references to relocated internal types.
  • Extracts native handles and existing public enums into focused files.
File Description
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​ISniNativeMethods.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeMethods.netcore.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeMethodsArm64.netfx.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeMethodsNotSupported.netfx.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeMethodsX64.netfx.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeMethodsX86.netfx.cs Imports native-SNI handles.
src/​Microsoft.Data.SqlClient/​src/​Interop/​Windows/​Sni/​SniNativeWrapper.cs Uses relocated native handles.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​Common/​AdapterUtil.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​Sql/​SqlDataSourceEnumeratorNativeHelper.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ActiveDirectoryAuthenticationTimeoutRetryHelper.cs Imports login token type.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​AlwaysEncryptedHelperClasses.cs Removes relocated metadata partials.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Connection/​ConnectionCapabilities.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Connection/​ServerInfo.cs Imports parser routing types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Connection/​SqlConnectionInternal.cs Imports parser, login, and token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​LocalDb/​LocalDbApi.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​LocalDB.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniCommon.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniError.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniHandle.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniLoadHandle.netcore.cs Imports parser and login types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniMarsConnection.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniMarsHandle.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniNpHandle.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniPacket.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniProxy.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniTcpHandle.netcore.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SslOverTdsStream.netcore.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​NativeSni/​SNIHandle.cs Extracts native connection handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​NativeSni/​SNILoadHandle.cs Moves native SNI loader.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​NativeSni/​SNIPacket.cs Extracts native packet handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​CallbackType.cs Extracts callback enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​DescribeParameterEncryptionResultSet1.cs Extracts result-set ordinals.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​DescribeParameterEncryptionResultSet2.cs Extracts result-set ordinals.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​DescribeParameterEncryptionResultSet3.cs Extracts result-set ordinals.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​LastIOTimer.cs Extracts I/O timer holder.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​EncryptionOptions.cs Extracts encryption options.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​FederatedAuthenticationFeatureExtensionData.cs Extracts federated-auth data.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​PreLoginHandshakeStatus.cs Extracts handshake status.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​PreLoginOptions.cs Extracts pre-login options.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​SqlFedAuthToken.cs Extracts federated-auth token.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Login/​SqlLogin.cs Extracts login state.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Packet.cs Moves packet reconstruction helper.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​PacketHandle.netcore.cs Moves .NET packet handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​PacketHandle.netfx.cs Moves Framework packet handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​ParsingErrorState.cs Extracts parsing-error enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​RunBehavior.cs Extracts parser run behavior.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​SessionHandle.netcore.cs Moves .NET session handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​SessionHandle.netfx.cs Moves Framework session handle.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​SniContext.cs Extracts SNI context enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​SslProtocolHelpers.cs Extracts TLS warning helper.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsEnums.cs Moves TDS constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsOperationStatus.cs Extracts operation-status enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParameterSetter.cs Relocates parameter setter.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParser.cs Moves core TDS parser.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserSessionPool.cs Moves parser session pool.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserState.cs Extracts parser-state enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStateObject.Multiplexer.cs Moves multiplexer implementation.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStateObject.cs Moves parser session state.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStateObjectFactory.cs Moves parser-state factory.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStateObjectManaged.netcore.cs Moves managed parser state.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStateObjectNative.cs Moves native parser state.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParserStaticMethods.cs Moves parser utilities.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsRecordBufferSetter.cs Moves structured-value writer.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsValueSetter.cs Moves TDS value writer.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​MultiPartTableName.cs Extracts multipart-name parsing.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​RoutingInfo.cs Extracts routing-token data.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​SqlFedAuthInfo.cs Extracts federated-auth metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​SqlMetaDataPriv.cs Consolidates private metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​SqlMetaDataUdt.cs Extracts UDT metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​SqlMetaDataXmlSchemaCollection.cs Extracts XML metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​SqlReturnValue.cs Extracts return-value metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​_SqlMetaData.cs Extracts column metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​_SqlMetaDataSet.cs Consolidates metadata-set logic.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​_SqlMetaDataSetCollection.cs Extracts metadata collection.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​_SqlRPC.cs Extracts RPC state.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SSPI/​NativeSspiContextProvider.cs Imports parser/native-SNI types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SSPI/​SspiContextProvider.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Server/​MetadataUtilsSmi.cs Imports parser metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Server/​ValueUtilsSmi.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlBuffer.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlBulkCopy.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCachedBuffer.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCollation.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Batch.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Encryption.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.NonQuery.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Reader.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Scalar.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Xml.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommandColumnEncryptionSetting.cs Extracts existing public enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnection.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionAttestationProtocol.cs Extracts existing public enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionColumnEncryptionSetting.cs Extracts existing public enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionIPAddressPreference.cs Extracts existing public enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionOptions.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionOverrides.cs Extracts existing public enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlConnectionStringBuilder.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCredential.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlDataReader.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlDbColumn.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlEnums.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlEnvChange.cs Imports token metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlInternalTransaction.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlMetaDataFactory.DataTypes.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlParameter.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlSecurityUtility.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlTransaction.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlUtil.cs Imports parser constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​TdsEnums.cs Removes relocated TDS constants.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​TdsParameterSetter.cs Removes relocated setter.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​TdsParserHelperClasses.cs Removes split-out helpers.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​TransactionRequest.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​TransparentNetworkResolutionState.cs Extracts TNIR state enum.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlTypes/​SqlVector.cs Imports parser types.
src/​Microsoft.Data.SqlClient/​tests/​FunctionalTests/​Microsoft.Data.SqlClient.FunctionalTests.csproj Updates relocated compile paths.
src/​Microsoft.Data.SqlClient/​tests/​FunctionalTests/​MultiplexerTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​FunctionalTests/​TdsParserStateObject.TestHarness.cs Moves harness namespace.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​SQL/​Common/​SystemDataInternals/​ConnectionHelper.cs Updates reflected parser names.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​SQL/​Common/​SystemDataInternals/​TdsParserHelper.cs Updates reflected parser name.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​ConnectionPool/​DbConnectionPoolAccessTokenTest.cs Imports login namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​Common/​AdapterUtilTest.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniPacketTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​SqlBulkCopyVariantTests.cs Imports parser token types.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​SqlMetaDataFactoryDataTypesTest.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​SqlMetaDataSetTest.cs Imports token namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​StateSnapshotPacketRecyclingTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​TdsParserStateObjectNativeTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​FeatureExtAckBoundsTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​IsolationLevelResetTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​TdsTokenBoundsTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​TdsParserDecimalTests.cs Imports parser namespace.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​TdsParserInternalsTest.cs Imports parser namespace.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

using System;
using System.Data;

namespace Microsoft.Data.SqlClient.Parser.Tokens;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

4 participants