A set of technologies in the .NET Framework for building web applications and XML web services.
Try adding TrustServerCertificate=True; to your connection string.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I've an application that uses WebAPI in .Net core 6 and uses Kestrel server. When calling HttpPost request, the code tries to inject data in DB but fails with error:
The certificate chain was issued by an authority that is not trusted.
Inner exception: A connection was successfully established with the server, but then an error occurred during the login process
The obvious resolution is to inject TrustServerCertificate=True in the connection string. But this is a security risk as it can trust invalid certificate.
I'm using Dapper package to communicate with Sql server database.
After investigation, I found that this happens when I refer Microsoft.Data.SqlClient package. If I replace with System.Data.SqlClient package, above error occurs no more and I don't have to inject TrustServerCertificate flag.
1) Can anyone let me know why this error is raised when I refer Microsoft.Data.SqlClient?
2) Which package (System.Data.SqlClient or Microsoft.Data.SqlClient) is recommended for the new development (i.e. .Net 6 and Kestrel)
Thanks,
Amit
A set of technologies in the .NET Framework for building web applications and XML web services.
Try adding TrustServerCertificate=True; to your connection string.
After adding Encrypt=False to the connection string, it worked!!!
Hi @Amit Potdar
I faced similar issues a few months back.
Here the solution [https://rijsat.com/2022/12/12/entity-framework-update-database-error-the-certificate-chain-was-issued-by-an-authority-that-is-not-trusted/
Update Your connection String as shown below.
We need to add additional parameters trusted_connection=true;encrypt=false; in the connection string.
This is because of SQL server update.
The default value of the Encrypt connection setting has been changed from false to true. With the growing use of cloud databases and the need to ensure those connections are secure, it’s time for this backwards-compatibility-breaking change.
Hi,
I found that this happens when I refer Microsoft.Data.SqlClient package. If I replace with System.Data.SqlClient package, above error occurs no more
System.Data.SqlClient is the ADO.NET old provider used by .NET Framework. The Microsoft.Data.SqlClient package was released in 2019 and it is the new package which supports both .NET Core and .NET Framework. You should prefer using the new package, which support new features in SQL Server.
https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient/
Please check the following document for Possible reasons and solutions for this error:
1) Can anyone let me know why this error is raised when I refer Microsoft.Data.SqlClient?
Probably the TLS 1.2 is not enabled. You might need to update the server to the last version.
Use the following document to determine whether your current version of SQL Server already has support for TLS 1.2
If you still do not succeed, then please execute: SELECT @@VERSION and provide the exact information of the version.
Had this issue today
Excel connection to SQL Data source, failed with this exact same message.
Turns out we only needed to install the SQL Client Tools v11 x64 and re-open the workbook and all worked again.