SQL connection: Target principal name incorrect

Tommy Lau 0 Reputation points
2024-07-02T07:13:14.3266667+00:00

Our Developer want to upgrade his website .net 8.0 from .net core 3.1, and downloaded System.Data.SqlClient (04.8.6),

Have fixed all issues in debug machine.

 

Problem occurs when published to the production website, has got the following error:

 

Win32Exception: The target principal name is incorrect.

SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)

 

 

            Further details form log is as below:

 

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 target principal name is incorrect.)

---> System.ComponentModel.Win32Exception (0x80090322): The target principal name is incorrect.

Windows development Internet Information Services
Developer technologies Visual Studio Other
SQL Server Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ZoeHui-MSFT 41,491 Reputation points
    2024-07-03T09:14:17.4966667+00:00

    Hi @Tommy Lau,

    Try adding TrustServerCertificate=True; or adding Encrypt=False to your connection string.

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    3 people found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2024-07-02T12:33:05.6933333+00:00

    To start with, he should use Microsoft.Data.SqlClient which has superceded System.Data.SqlClient.

    Since recent versions of Microsoft.Data.SqlClient defaults to require an encrypted connection, this may lead to other errors, but we will see.

    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.