How to fix error occurred during the pre-login handshake after upgrading SqlClinet

Zoran Gladoic 25 Reputation points
2024-03-06T15:31:33.9566667+00:00

I upgraded project from .NET 6 to .NET 8, along with the packages. Sql Client is upgraded from 2.1.4 to 5.1.1 version contained in EF Core 8.0.1 package. We are using Azure DB, and there is no error in .NET 6 version with older SqlClinet. I'm aware of breaking changes in EF7 that set default behavior Encrypt=True, which is already set in Connection string.

Connection string:

Server=tcp:<db>;Database=<db name>;User ID=<user>;Password=<pass>;Trusted_Connection=False;Encrypt=True;

Error on Azure DevOps build stage when update database commands is executed:

Error Number:-2146893019,State:0,Class:20

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)

On Azure DB always throws exception, no matter connection string parameters.

On locally DB it works when conn string contains Encrypt=True or TrustServerCertificate=True, otherwise

throws error:

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 issued by an authority that is not trusted.)

On Azure SQL Connectivity is set to Default and TLS is unchecked which should allow TLS 1.0, 1.1, 1.2., and Certificate is existing.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
751 questions
Azure SQL Database
{count} votes

Accepted answer
  1. ShaktiSingh-MSFT 15,421 Reputation points
    2024-03-08T08:46:18.1666667+00:00

    Hi Zoran Gladoic,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Solution in cx verbatim:

    This is resolved. After some discovery, I found it is running against SQL container, not Azure DB, and I updated the wrong connection string.

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Zoran Gladoic 25 Reputation points
    2024-03-07T08:50:15.01+00:00

    This is resolved. After some discovery, I found it is running against SQL container, not Azure DB, and I updated the wrong connection string.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.