Skip to content

Backwards incompatibility between Microsoft.Data.SqlClient.SqlConnectionStringBuilder and System.Data.SqlClient.SqlConnectionStringBuilder #1780

@captain-seablade

Description

@captain-seablade

Describe the bug

There is a significant discrepancy between the two SqlConnectionStringBuilder types as far as their internal keywords are defined.
The keywords can be found in the internal class DbConnectionStringKeywords. An example:

internal const string TrustServerCertificate = "Trust Server Certificate";

However, in the .NET Framework version of the System.Data.SqlClient, the same keywords class has it defined differently:

https://referencesource.microsoft.com/System.Data/R/6a6a501b9f709c06.html

This is an example keyword, but there are more keywords where this is an issue.

Here's the code excerpt for both:

Microsoft.Data.SqlClient

...
internal const string TrustServerCertificate = "Trust Server Certificate";
...

System.Data.SqlClient

...
internal const string TrustServerCertificate = "TrustServerCertificate";
...

When a connection string is built using the Microsoft.Data.SqlClient.SqlConnectionStringBuilder, it cannot be deconstructed within the System.Data.SqlClient.SqlConnectionStringBuilder as it throws an exception indicating that the keyword is not supported.

To reproduce

Run the following code in a project that is using Microsoft.Data.SqlClient:

var csb = new SqlConnectionStringBuilder { TrustServerCertificate = true };
var cs = csb.ConnectionString;

Take the connection string from that and then apply it to a different set of code using the System.Data.SqlClient:

var connectionString = "Trust Server Certificate=True";
var csb = new SqlConnectionStringBuilder(connectionString);
var cs = csb.ConnectionString;

The following exception will occur:

System.ArgumentException: 'Keyword not supported: 'trust server certificate'.'

Expected behavior

I would expect that the keywords would match and thus the connection strings would be interchangeable.

Further technical details

N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions