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.

Internet Information Services
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,178 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.
13,948 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 112.7K Reputation points MVP
    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

  2. ZoeHui-MSFT 37,376 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.

    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.