Skip to content

Conversation

@paulmedynski
Copy link
Contributor

@paulmedynski paulmedynski commented Dec 4, 2025

Description

This PR updates the UserAgent feature (once again) to employ the latest pipe-delimited format. The previous JSON format code has been removed.

The latest spec is here: SQL Drivers User Aget V1

Testing

  • Added unit tests for the new UserAgent static class.
  • Updated existing TDS tests to expect the new format.
  • Manually tested with a development version of SQL Server that supports the UserAgent feature extension.

@paulmedynski paulmedynski added this to the 7.0.0 milestone Dec 4, 2025
@paulmedynski paulmedynski requested a review from a team as a code owner December 4, 2025 16:28
Copilot AI review requested due to automatic review settings December 4, 2025 16:28
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 transitions the UserAgent feature from a JSON-based format to a pipe-delimited format for the TDS LOGIN7 USERAGENT Feature Extension. The change simplifies the implementation by eliminating JSON serialization overhead and aligns with the latest specification.

Key Changes:

  • Replaced JSON-serialized UserAgent with a pipe-delimited string format (1|MS-MDS|{version}|{OS}|{arch}|{OS info}|{runtime info})
  • Removed version byte from the feature extension payload (previously 1 byte for version + JSON, now just the UCS-2 encoded pipe-delimited string)
  • Changed encoding from UTF-8 to UCS-2 (little-endian Unicode)

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/UserAgent.cs New implementation of UserAgent class with pipe-delimited format, replacing the previous JSON-based implementation
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/UserAgent/UserAgentInfo.cs Removed - old JSON-based UserAgent implementation
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/UserAgent/UserAgentInfoDto.cs Removed - DTO for JSON serialization, no longer needed
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs Updated to use new pipe-delimited format; removed version byte from payload; updated parameter types from byte[] to ReadOnlyMemory<byte>
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsEnums.cs Removed constants for version byte and SQL_PROVIDER_NAME that are no longer used
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlException.cs Replaced TdsEnums.SQL_PROVIDER_NAME with direct reference to DbConnectionStringDefaults.ApplicationName
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlError.cs Replaced TdsEnums.SQL_PROVIDER_NAME with direct reference to DbConnectionStringDefaults.ApplicationName
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs Updated documentation comment for EnableUserAgent property
src/Microsoft.Data.SqlClient/tests/UnitTests/UserAgentTests.cs New comprehensive unit tests for the pipe-delimited UserAgent implementation
src/Microsoft.Data.SqlClient/tests/UnitTests/UserAgentInfoTests.cs Removed - tests for old JSON-based implementation
src/Microsoft.Data.SqlClient/tests/UnitTests/TdsParserInternalsTest.cs Updated tests to expect new pipe-delimited format without version byte
src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionTests.cs Updated integration test to validate new UserAgent format
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/UdtSerialization/NativeSerializationTest.cs Added DisableDiscoveryEnumeration to improve test performance (unrelated optimization)
src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/GenericTdsServer.cs Added comment clarification (cosmetic change)
src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj Updated project file to reference new UserAgent.cs and remove old files
src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj Updated project file to reference new UserAgent.cs and remove old files
spec/user-agent-v1.jsonc Removed - JSON schema specification no longer applicable

Copy link
Contributor Author

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

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

Commentary for reviewers, and things for me to fix.

// internal tdsparser constants


public const string SQL_PROVIDER_NAME = DbConnectionStringDefaults.ApplicationName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unnecessary level of indirection here, so removing this in favour of ApplicationName.

[MemberData(nameof(SerializedNonNullPrimitiveTypeValues))]
[MemberData(
nameof(SerializedNonNullPrimitiveTypeValues),
DisableDiscoveryEnumeration = true)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated change to suppress xUnit warnings.

int expectedDataLen = 1 + payload.Length;
Assert.Equal(expectedDataLen, dataLenFromStream);

Assert.Equal(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pipe-delimited format doesn't include a version byte. There is a version field embedded in the pipe-delimeted payload.

Copilot AI review requested due to automatic review settings December 8, 2025 14:03
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 17 out of 17 changed files in this pull request and generated 2 comments.

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.

2 participants