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.
Summary
GetSchema("DataTypes")never reports thejsontype against Azure SQL, even though Azure SQL supports it.Cause
Rows in the
DataTypescollection are filtered by the version the server reports.SqlMetaDataFactory.SupportedByCurrentVersioncompares the row'sMinimumVersionagainstConnectionCapabilities.ServerVersionas a string, and thejsonrow is declared from17.00.000.0onwards: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.xxxxwhatever it supports, so the comparison excludes the row.This affects only the newest types. Every other row is declared at
10.00.000.0or below, which12.00satisfies.Repro
Against Azure SQL, on a database where
jsoncolumns can be created:Suggested fix
The driver already negotiates
jsonsupport through a feature extension (FEATUREEXTACKtoken0x0D), andConnectionCapabilitiescarries the result. That is authoritative and correct on both Azure SQL and on-premises, unlike the reported version.SqlMetaDataFactoryis constructed with the fullConnectionCapabilities, so the value is already available where the collection is built. #4501 takes this approach for thevectortype:Doing the same for
jsonwould 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 newvectortype, which has not shipped.