Trust server certificate error

salilsingh-9961 351 Reputation points
2022-12-29T10:54:52.32+00:00

Hi Team,

I am trying to run a script by connecting to SQL Server, getting below error message -

A connection was successfully established, but a trusted certificate is not installed on the computer running SQL Server. Please set up a trusted certificate on the server. Refer to this link for further help: https://support.microsoft.com/en-us/help/2007728/error-message-when-you-use-ssl-for-connections-to-sql-server-the-certi

Note: Selecting the 'Trust server certificate' check box will connect to the server, however this may not be secure and therefore is not recommended.

    Error - Server certificate not trusted.  

Can you please let me know how to resolve this error. Any link will be helpful here.

Thanks,
Salil

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. PatriceSc 176 Reputation points
    2022-12-29T12:46:15.437+00:00

    Hi,

    Some more context could help (PowerShell 7.x maybe?) but for now it seems related to https://techcommunity.microsoft.com/t5/sql-server-blog/released-general-availability-of-microsoft-data-sqlclient-4-0/ba-p/2983346 ie :

    • a short term fix is to use Encrypt=false in the connection string as you are not using yet a trusted certificate
    • the long term fix is to start using trusted certificates on SQL Server so that the communication is encrypted (much like at some point we have gone from http to https)

    If part of a company see rather with SQL Server/IT admins. If an individual you could consider to give it a try with a free certificate provider such as https://www.naturalborncoder.com/sql/2019/08/30/how-to-configure-sql-server-to-use-lets-encrypt-certificates/

    0 comments No comments

  2. Erland Sommarskog 130.9K Reputation points MVP Volunteer Moderator
    2022-12-29T22:29:13.223+00:00

    The proper fix for this error depends on the situation. If you encounter this at home because you are running Azure Data Studio against your local lab server, there is little reason not to take the easy route and trust the server certificate.

    On the other hand, if you are connecting to a server instance where there is some degree of sensitivity, be that in the data, or the intellectual property in the source code in the stored procedures, you should absolutely consider to install a proper certificate on the server, and then install that certificate as a trusted certificate on the clients that connect.

    You may ask, what security do you gain? The communication with SQL Server is always encrypted. But if you trust the server certificate, you don't know what you are trusting. It could be the server's. It could be a certificate from a man-in-the-middle who decrypts everything you send and everything that comes from SQL Server, and thus steals your data. If you have certificate installed, you can have better faith that this is not happening.

    In the past, the default in all APIs was that encryption was optional, but Microsoft has changed the default across the board in all their APIs, and when you are hit by it, depends on the application you are using. I noticed that the most recent release of Azure Data Studio defaults to encryption being mandatory.


Your answer

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