Results 1 to 15 of 15

Thread: The certificate chain was issued by an authority that is not trusted

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    The certificate chain was issued by an authority that is not trusted

    I have been wrestling with this error and can't seem to find a solution. I've tried downloading versions 17 & 18 of the Microsoft ODBC Driver for SQL Server and it's still not working. I have attached an screenshot of my code.

    Name:  DBError.jpg
Views: 865
Size:  27.5 KB
    Blake

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: The certificate chain was issued by an authority that is not trusted

    If you are using SqlClient then odbc isn't getting involved, updating odbc drivers won't affect this.

    https://learn.microsoft.com/en-us/tr...en-you-connect is probably worth a read though.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    Wow, I opened the MMC and there is NO list of Certs. See image below!

    Name:  MMC.jpg
Views: 804
Size:  12.4 KB
    Blake

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: The certificate chain was issued by an authority that is not trusted

    If all you did was open MMC, then yeah, you aren't going to see certificates, or anything else for that matter.

    Once MMC is opened, you need to click File->Add/Remove Snap-in, click the Add button, and select Certificates, and go from there.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    I see what your saying. Here is the result of doing as you said.

    Name:  MMC.jpg
Views: 794
Size:  20.5 KB

    I also looked under the "Trusted Root Certification Authorities" and didn't see any cert that had SQL Server in in. I'm not sure what I'm looking for so it might be there and I just don't recognize it.
    Blake

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: The certificate chain was issued by an authority that is not trusted

    https://stackoverflow.com/questions/...sted-when-conn

    Based on the connection string, this appears to be your own PC that you are connecting to. Workarounds for non-production, non-publicly accessible systems would be to either set Trusted_Connection to false, or add TrustServerCertificate=True to the connection string.

    Good luck.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    I added "TrustServerCertificate=True" and that worked...or at least allowed me to execute the program. However, the connection state is 0 (not openend).

    And you are correct, it is my machine and I'm only using it to test things. I'm trying to get back into IT so I'm doing some self-training. Thanks for your help!
    Last edited by blakemckenna; Aug 10th, 2023 at 06:51 PM.
    Blake

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    I am using my laptop with a local instance of SQL Server 2019 and Visual Studio 2019 Community edition. I don't know what else to do with this issue. I don't know where the problem is. Here is my most recent code as well as an image.

    Code:
    //using System;
    //using System.Collections.Generic;
    //using System.ComponentModel;
    using System.Data;
    using Microsoft.Data.SqlClient;
    //using System.Drawing;
    //using System.Linq;
    //using System.Text;
    using System.Windows;
    //using System.Threading.Tasks;
    //using Prism.Services.Dialogs;
    
    namespace WpfApp1
    {
        class DatabaseIO
        {
            DataSet ds;
            SqlCommand sqlComm;
            SqlParameter sqlParm;
            SqlConnection sqlCnn;
    
            public bool OpenDBConnection()
            {
                //string connectionString = "Server=BLAKES-PC;Database=Northwind;User Id='';Password='';Trusted_Connection=True;TrustServerCertificate=True;";
                string connectionString = "Data Source = (local); Initial Catalog = Northwind;Integrated Security=SSPI;User Id='';Password=''";
                using (SqlConnection sqlCnn = new SqlConnection(connectionString))
                {
                    sqlCnn.Open();
    
                    MessageBox.Show("State: {0}", sqlCnn.State.ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question);
    
                    if (sqlCnn.State.Equals("Open"))
                    {
                        return true;
                    }
    
                    return false;
                }
    
            }
            //
            //
            //
            public void GetStateAbbr(DataSet ds)
            {
    
    }
        }
    }
    Name:  DBError.jpg
Views: 808
Size:  20.7 KB
    Last edited by blakemckenna; Aug 11th, 2023 at 02:26 PM.
    Blake

  9. #9
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: The certificate chain was issued by an authority that is not trusted

    What happens if you try adding both the "rusted_Connection=True;TrustServerCertificate=True" entries to the connection string for the local database?

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    I tried adding those properties and it executed, however, the database still isn't open...
    Blake

  11. #11
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: The certificate chain was issued by an authority that is not trusted

    Quote Originally Posted by blakemckenna View Post
    I tried adding those properties and it executed, however, the database still isn't open...
    So did you get a different error, or just no results?

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    No results...I popup a messagebox saying "Database OPEN" or "Database CLOSED" and it comes up CLOSED.
    Blake

  13. #13
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: The certificate chain was issued by an authority that is not trusted

    Quote Originally Posted by blakemckenna View Post
    No results...I popup a messagebox saying "Database OPEN" or "Database CLOSED" and it comes up CLOSED.
    Code:
    sqlCnn.State.Equals("Open")
    seems an unusual way of checking an enum, I suspect this is the problem. If you want to compare the status then just use
    Code:
    if(sqlCnn.State == ConnectionState.Open)

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: The certificate chain was issued by an authority that is not trusted

    I believe that worked but I can't tell because I'm throwing an exception and don't know why. I'm sure it's because of my lack of knowledge of C#. I'm trying to learn this language so I can re-enter the IT world. Here is the message I'm getting.

    Name:  ExceptionError.jpg
Views: 783
Size:  22.8 KB
    Blake

  15. #15
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: The certificate chain was issued by an authority that is not trusted

    Quote Originally Posted by blakemckenna View Post
    I believe that worked but I can't tell because I'm throwing an exception and don't know why. I'm sure it's because of my lack of knowledge of C#. I'm trying to learn this language so I can re-enter the IT world. Here is the message I'm getting.

    Name:  ExceptionError.jpg
Views: 783
Size:  22.8 KB
    The image is a bit difficult to read, generally it is better to just put the error message itself into your post.

    That seems a really strange exception to be thrown on such a simple line of code. Try putting a breakpoint on that line and step through the code, just to see what happens.

    Although, you are also declaring a variable with the same name in the OpenDBConnection method - is this what you intended to do?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width