Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
captain-seablade opened this issue Sep 28, 2022 · 3 comments

Comments

@captain-seablade
Copy link

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

@JRahnama
Copy link
Contributor

@captain-seablade that change was decided and made as a breaking change in earlier stage of M.D.SqlClient in PR #534.

@captain-seablade
Copy link
Author

Ok, thank you. I attempted a search for anything related to breaking changes regarding this issue and I was unable to find the PR you mentioned or other supporting details. Thank you for the information. I'll adjust accordingly and add workarounds.

@JRahnama
Copy link
Contributor

Closing as not an issue,

majorsilence added a commit to TownSuite/TownSuite.MultiTenant that referenced this issue Aug 29, 2023
…strings

see dotnet/SqlClient#1780 and dotnet/SqlClient#534

  Application Intent (previously ApplicationIntent)
        Connect Retry Count (previously ConnectRetryCount)
        Connect Retry Interval (previously ConnectRetryInterval)
        Pool Blocking Period (previously PoolBlockingPeriod)
        Multiple Active Result Sets (previously MultipleActiveResultSets)
        Multiple Subnet Failover (previously MultiSubnetFailover)
        Transparent Network IP Resolution (previously TransparentNetworkIPResolution)
        Trust Server Certificate (previously TrustServerCertificate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants