-
Notifications
You must be signed in to change notification settings - Fork 299
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
SQLConnectionStringBuilder 5.0 is not Backwards Compatible with appSettings.json #1894
Comments
Hi @srothkin, that sounds like a bug and will need to be investigated. As a workaround, could you try setting |
With SqlClient 4.0 it IS reading the encrypt value from appSettings.json. We have automated unit tests that verify this with SqlClient 4.0 and break with 5.0.1. |
Health check fails with TrustServerCertificate=true and Encrypt=True. |
So this blocks us from moving to SqlClient 5 |
Thanks for the update. Were you able to connect without using the appSettings.json with that connection string with your health check failure with |
Actually TrustServerCertificate=true does work (there was another issue when I tested it yesterday). I'll get you a repro app later today. |
Automated unit tests in this sample all pass with SqlClient 4 but some fail with SqlClient 5.1 |
Thanks @srothkin for providing the repro sample. I ran the tests, and it was reproducible. So far, I've briefly looked into the first failed test in the list i.e. |
Hi @srothkin , we did some investigation and tried to see if it invokes any of our conversion behavior in |
It's not reproducible using JsonXXX types to serialize and de-serialize into and from a stream. Basically, the underlying functions can't resolve or assign the cc @roji |
@DavoudEshtehari @lcheunglci am I understanding correctly, that the root cause here is that SqlConnectionStringBuilder.Encrypt is a now class (SqlConnectionEncryptOption), rather than a bool or enum, and therefore the deserialization of the options from appSettings.json isn't working properly? I admit I haven't yet seen arbitrary classes as connection string components, I can imagine that would cause trouble in various systems interacting with connection strings... |
Could some serilisation hints be added? |
Just curious: was there any specific reason to switch to a class rather than to an enum (which is what the class conceptually seems to be)? I didn't follow this change so am probably unaware of the details... |
Ironically, it was to add backward compatibility so that |
Oh I see, via the implicit casting operator. I'm pretty sure you may find some other cases when arbitrary classes in connection strings won't work well. For example, people sometimes bind a Winforms PropertyGrid (I think that's what it's called) to a connection string builder, to allow users to manipulate the settings etc. This works with the primitive types, but I'm not sure it would work well with arbitrary classes. VS DDEX may be another problem. |
Thanks @roji , if that's the case, it looks like we may want to consider a different implementation to add backward compatibility support. |
Describe the bug
With SqlClient 4, standard appSettings.json standard config file mapping from something like
{ "MyDb": { "Components": { "UserID": "blah", "Password": "foo", "DataSource": "hostname", "Encrypt": false } } }
to a SQLConnectionStringBuilder property
worked. With SqlClient 5.0, the resulting connection string is now returning Encrypt=True
I've tried changing encrypt value in json to "false", "False", "SqlConnectionEncryptOption.Optional", and "Optional". All of those still result in connection string with Encrypt=True.
To reproduce
Expected behavior
Expecting appSettings.json (or environment variable override of it) setting of "Encrypt": false to result in Encrypt=false in resulting connection string.
Further technical details
Microsoft.Data.SqlClient version: 5.0.1
.NET target: 6
SQL Server version: n/a
Operating system: Windows 10
Additional context
We're using the SqlConnectionStringBuilder to assemble/validate connection string components that are coming from different places (environment variables in helm chart, Azure keyvault, appSettings.json) into a single connection string. Our environment doesn't yet support encrypt=true/mandatory.
The text was updated successfully, but these errors were encountered: