Skip to content

Fix | Build DataTypes table in code, add json data type#3858

Merged
apoorvdeshmukh merged 10 commits into
dotnet:mainfrom
edwardneal:fix/issue-3833-json
May 14, 2026
Merged

Fix | Build DataTypes table in code, add json data type#3858
apoorvdeshmukh merged 10 commits into
dotnet:mainfrom
edwardneal:fix/issue-3833-json

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

Description

This PR makes two related changes: it populates the DataTypes table returned by SqlConnection.GetSchema in code rather than by deserializing an embedded XML resource, and then adds the json data type to this table.

In the process of adding tests, I also noticed that there wasn't a coherent view of whether or not the json data type was present, so added one. This also led me to notice that we're not running JSON-based tests on SQL 2025, so I changed their test criteria to make sure this happens. This is essentially the same situation as #3794, and I'm expecting some degree of conflicts depending upon the order they're merged in.

It should be possible to move commit-by-commit, but 2f907ed is probably the bulkiest. This commit populates the fields in the DataTypes table based on the value of fields in the MetaType instances for each type.

Issues

Contributes to #3833.
Contributes to #3372.

I'm conscious that #3833 refers to the json and the vector types. I've not included the vector type because I don't know whether we should treat vector({0}[, float32]) and vector({0}, float16) as two different data types. There's also a little extra plumbing to deal with within SqlVector<float> and in the tests (which #3794 introduces.)

Testing

I've manually verified that all fields for all existing data types are identical between main and this branch. I've also added a new test to prove that no data types have been omitted.

SqlClient cannot connect to SQL Server 2000 instances, so the minimum server version is 9.0.
* Remove data type entries with a maximum version below this.
* Remove the minimum version constraint where this constraint will always be true.
This enables the JSON tests to run against SQL Server 2025.
Also correct a comment in LoadDataTypesDataTables.
Copy link
Copy Markdown
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 refactors the DataTypes schema metadata population from an XML-based approach to a code-based approach, and adds support for the json data type. It introduces a new IsJsonSupported property to consolidate SQL Server version detection for JSON features and updates all JSON-related tests to use this unified check.

Key Changes

  • Replaced XML deserialization for the DataTypes metadata table with programmatic population using MetaType introspection
  • Added the json data type to the schema with appropriate metadata (minimum version 17.00.000.0, long type, not best match)
  • Introduced DataTestUtility.IsJsonSupported property to centralize JSON support detection across tests

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
JsonTest.cs Updated conditional test attributes to use IsJsonSupported instead of Azure-specific checks
JsonStreamTest.cs Updated conditional test attributes to use IsJsonSupported
JsonBulkCopyTest.cs Updated conditional test attributes to use IsJsonSupported
ConnectionSchemaTest.cs Added new test to verify DataTypes schema and validate json type presence based on server support
DataTestUtility.cs Added IsJsonSupported property and IsTypePresent helper method for SQL Server feature detection
SqlMetaData.xml Removed DataTypesTable XML section (695 lines)
SqlMetaDataFactory.cs Updated to call new code-based DataTypes population instead of XML deserialization
SqlMetaDataFactory.DataTypes.cs New file containing all DataTypes table population logic with helper methods for different type categories
Microsoft.Data.SqlClient.csproj (netfx/netcore) Added reference to new SqlMetaDataFactory.DataTypes.cs file

@apoorvdeshmukh
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski paulmedynski self-assigned this Dec 23, 2025
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to inactivity for more than 30 days.

If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days.

@github-actions github-actions Bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 21, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions Bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 24, 2026
@paulmedynski paulmedynski modified the milestones: 7.0.1, 7.1.0-preview1 Mar 9, 2026
mdaigle
mdaigle previously approved these changes Mar 25, 2026
@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Mar 25, 2026

/azp run

@apoorvdeshmukh
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@edwardneal
Copy link
Copy Markdown
Contributor Author

Thanks @paulmedynski and @apoorvdeshmukh. I think my comment may be a bit redundant, but... I've just merged!

@paulmedynski paulmedynski enabled auto-merge (squash) May 11, 2026 16:46
paulmedynski
paulmedynski previously approved these changes May 11, 2026
@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board May 11, 2026
Copy link
Copy Markdown
Contributor

@apoorvdeshmukh apoorvdeshmukh left a comment

Choose a reason for hiding this comment

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

@edwardneal There are some test failures. Check the testcase TestJsonWithMARS

@github-project-automation github-project-automation Bot moved this from In review to In progress in SqlClient Board May 13, 2026
@paulmedynski paulmedynski added the Author attention needed PRs that require author to respond or make updates to PR. label May 13, 2026
@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board May 13, 2026
This was manually constructing a connection string, which didn't work on one CI leg.
auto-merge was automatically disabled May 13, 2026 18:14

Head branch was pushed to by a user without write access

@edwardneal
Copy link
Copy Markdown
Contributor Author

I see the problem, thanks @apoorvdeshmukh. That test was manually building up a connection string to enable MARS, but didn't include the terminator. I've swapped the approach out for a more standard SqlConnectionStringBuilder, and this should now pass.

@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@paulmedynski paulmedynski removed the Author attention needed PRs that require author to respond or make updates to PR. label May 13, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.82%. Comparing base (be95ca2) to head (1215739).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3858      +/-   ##
==========================================
- Coverage   65.96%   64.82%   -1.15%     
==========================================
  Files         275      271       -4     
  Lines       42993    66065   +23072     
==========================================
+ Hits        28361    42826   +14465     
- Misses      14632    23239    +8607     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.82% <100.00%> (?)

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.

Copy link
Copy Markdown
Contributor

@apoorvdeshmukh apoorvdeshmukh left a comment

Choose a reason for hiding this comment

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

LGTM

@apoorvdeshmukh apoorvdeshmukh merged commit fbfd827 into dotnet:main May 14, 2026
303 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board May 14, 2026
@edwardneal edwardneal deleted the fix/issue-3833-json branch May 14, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants