Skip to content

Microsoft.DataSqlTypes.SqlJson is missing ToString #3424

@shueybubbles

Description

@shueybubbles

Describe the bug

the breaking change is that this call now returns the name of a Type instead of the string value of the json column:

                case SqlDataType.Json:
                    formattedValue = String.Format(
                        CultureInfo.InvariantCulture,
                        "CAST({0} AS Json)", SqlSmoObject.MakeSqlString(this.reader.GetProviderSpecificValue(columnIndex).ToString()));
                    break;

GetProviderSpecificValue(i) returns an instance of Microsoft.Data.SqlTypes.SqlJson, whose ToString() method doesn't have an implementation.
This feels like a bug in the driver, to me. It should return this.Value

-  (Microsoft.Data.SqlTypes.SqlJson)this {Microsoft.Data.SqlTypes.SqlJson} Microsoft.Data.SqlTypes.SqlJson
  IsNull false bool
  Value "[]" string
  _isNull false bool
  _jsonString "[]" string

To reproduce

The corresponding SMO code is at https://github.com/microsoft/sqlmanagementobjects/blob/1b5ffd2300252ddc4103da2c792c999a5ac6193a/src/Microsoft/SqlServer/Management/Smo/DataEnumerator.cs#L950

Expected behavior

ToString() should return the JSON text

Additional context

Customers using SMO to copy JSON data are blocked from upgrading to SqlClient 6.

Metadata

Metadata

Assignees

Labels

Area\JsonUse this for issues that are targeted for the Json feature in the driver.Enhancement 💡Issues that are feature requests for the drivers we maintain.P2Use to label moderate priority issue - impacts atleast more than 1 customer.Public API 🆕Issues/PRs that introduce new APIs to the driver.Triage Done ✔️Issues that are triaged by dev team and are in investigation.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions