Skip to content

GetSchema("DataTypes") does not report the json type against Azure SQL #4592

Description

@apoorvdeshmukh

Summary

GetSchema("DataTypes") never reports the json type against Azure SQL, even though Azure SQL supports it.

Cause

Rows in the DataTypes collection are filtered by the version the server reports. SqlMetaDataFactory.SupportedByCurrentVersion compares the row's MinimumVersion against ConnectionCapabilities.ServerVersion as a string, and the json row is declared from 17.00.000.0 onwards:

https://github.com/dotnet/SqlClient/blob/main/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlMetaDataFactory.DataTypes.cs#L61-L62

Azure SQL reports 12.00.xxxx whatever it supports, so the comparison excludes the row.

This affects only the newest types. Every other row is declared at 10.00.000.0 or below, which 12.00 satisfies.

Repro

Against Azure SQL, on a database where json columns can be created:

using SqlConnection connection = new(azureConnectionString);
connection.Open();

foreach (DataRow row in connection.GetSchema("DataTypes").Rows)
{
    if ((string)row["TypeName"] == "json")
    {
        Console.WriteLine("found");
    }
}
// nothing is printed

Suggested fix

The driver already negotiates json support through a feature extension (FEATUREEXTACK token 0x0D), and ConnectionCapabilities carries the result. That is authoritative and correct on both Azure SQL and on-premises, unlike the reported version.

SqlMetaDataFactory is constructed with the full ConnectionCapabilities, so the value is already available where the collection is built. #4501 takes this approach for the vector type:

if (vectorVersion != TdsEnums.VECTOR_VERSION_NOT_SUPPORTED)
{
    AddVectorType();
}

Doing the same for json would make the two consistent.

Why this is filed separately

json's current behaviour has shipped, so changing it is a behavioural change that deserves its own discussion. #4501 only avoided introducing the same gap for the new vector type, which has not shipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\EngineeringUse this for issues that are targeted for changes in the 'eng' folder or build systems.

    Type

    No type

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions