Closed CanisHelix closed 2 years ago
The only idea I have is that installing EntityFrameworkCore.Exceptions.SqlServer
also installs 4.1.0
version of Microsoft.Data.SqlClient
which for some reason fails to open connection in your specific scenario. When you uninstall EntityFrameworkCore.Exceptions.SqlServer
your app uses a newer version of Microsoft.Data.SqlClient
that doesn't have the same issue.
You can verify my idea by building a simple app that uses ADO.NET to connect to the database and open db connection. Try it with different versions of Microsoft.Data.SqlClient
So I was able to work around it by adding TrustServerCertificate=True;
to the ConnectionString, something I never normally need to do.
Edit: Checked my project and it did install Microsoft.Data.SqlClient, Version=4.1.0.0
, removing EntityFrameworkCore.Exceptions.SqlServer
puts it back to Microsoft.Data.SqlClient, Version=2.0.20168.4
Researching quickly found this: https://docs.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/7.0/microsoft-data-sqlclient-updated-to-4-0-1
So it's a breaking change in SqlClient 4.0 to change defaults. Maybe a note in the getting-started might help others in the future.
TrustServerCertificate
tells SqlClient
not to validate the server certificate which isn't a good thing. If you don't need encryption at all you can set Encrypt=false
in your connection string to revert to the old behavior.
See this issue for more details: Reconsider throwing errors by default when the server uses a self-signed certificate
I guess the other option is to figure out how to get a trusted certificate inside MSSQL on docker, for a .lan domain hosted server.
@Giorgi so wait, why is this closed? What is the fix?
Just add Encrypt=false
to your docker string?
Do you need to update your dependencies to the newer SqlClient?
Here you go https://github.com/Giorgi/EntityFramework.Exceptions/pull/50
Updating SqlClient
to 5.0 won't change anything. The breaking change was from upgrading an older version of SqlClient
to version 4. In this version, by default Encrypt
is set to True causing the error to be thrown when the server certificate is self-signed. I don't think version 5 reverts to False.
I have added EntityFrameworkCore.Exceptions.SqlServer 6.0.3 to my working Worker Project that uses EFCore 6.0.7 and as soon as I do so, I can no longer run my project. Adding the following does not make it work either.
The only way to fix the connection to my database is to remove the Nuget. Simply having it installed in my project breaks connections to SQLServer. If I copy the files from this project into my project directly for SqlServer, then it works. So something about the nuget is causing issues. I have repeated this test 10 times now, consistently with the following results. Why does this nugget break the connection?