how to solve the error "Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - La chaîne de certificats a été"

Marnelle M'BENGUET 20 Reputation points
2023-05-23T09:49:55.54+00:00

Hi I try to connect my asp.net core api to a sql server database I encounter an error like: "Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was provided by an authority that is not trusted.)", this error I encountered long before and had add the following properties: "TrustServerCertificate=True" and "Trusted_connection=True" but I encounter the same error I added these properties but I have the same error, what can cause this?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,220 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,833 questions
{count} votes

4 answers

Sort by: Most helpful
  1. imilton 5 Reputation points
    2023-06-13T07:25:30.92+00:00

    I fixed it adding on my connection string the following parameters:

    "Trusted_Connection=true;encrypy=false;"
    
    1 person found this answer helpful.

  2. Erland Sommarskog 102K Reputation points MVP
    2023-05-23T22:09:42.2566667+00:00

    I would say that the best solution is to talk with your IT folks to have a proper certificate installed on the SQL Server machine, and added to the trusted certificate store on the clients.

    By the way, Trusted_connection is just a synonym for Integrated Security. It is not relation to connection security as such.


  3. SurferOnWww 1,916 Reputation points
    2024-04-10T02:30:10.18+00:00

    Probably your SQL Server does not support TLS 1.2. Please see the following Microsoft document:

    Login-phase errors

    There was change in Microsoft.Data.SqlClient 4.0 as described below:

    New features in 4.0

    "The default value of the Encrypt connection setting has been changed from false to true."

    0 comments No comments

  4. Martinho Sebastião 0 Reputation points
    2024-05-05T19:54:35.22+00:00

    Hello,

    1 - Check the type of authentication configured on the SQL Server.

    2 - See the example below of a complete connection string, and adapt it to your data:

    "ConnectionStrings": {

    "DefaultConnection": "Server=MyServerNameOrHostIP,PortNumber;Initial Catalog=Mydatabse;User Id=YourUser;Password=YourPassword;Persist Security Info=False;Trusted_Connection=False;Encrypt=False;TrustServerCertificate=True;"

    }

    If it works or you need clarification, leave a comment.

    0 comments No comments