|
-
Aug 10th, 2023, 03:38 PM
#1
Thread Starter
PowerPoster
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.
-
Aug 10th, 2023, 03:58 PM
#2
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.
-
Aug 10th, 2023, 04:28 PM
#3
Thread Starter
PowerPoster
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!
-
Aug 10th, 2023, 05:49 PM
#4
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.
-
Aug 10th, 2023, 06:14 PM
#5
Thread Starter
PowerPoster
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.

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.
-
Aug 10th, 2023, 06:28 PM
#6
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.
-
Aug 10th, 2023, 06:40 PM
#7
Thread Starter
PowerPoster
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
-
Aug 11th, 2023, 02:22 PM
#8
Thread Starter
PowerPoster
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)
{
}
}
}
Last edited by blakemckenna; Aug 11th, 2023 at 02:26 PM.
Blake
-
Aug 11th, 2023, 02:44 PM
#9
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?
-
Aug 11th, 2023, 02:48 PM
#10
Thread Starter
PowerPoster
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...
-
Aug 11th, 2023, 03:45 PM
#11
Re: The certificate chain was issued by an authority that is not trusted
 Originally Posted by blakemckenna
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?
-
Aug 11th, 2023, 03:52 PM
#12
Thread Starter
PowerPoster
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.
-
Aug 11th, 2023, 04:25 PM
#13
Re: The certificate chain was issued by an authority that is not trusted
 Originally Posted by blakemckenna
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)
-
Aug 11th, 2023, 05:06 PM
#14
Thread Starter
PowerPoster
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.
-
Aug 11th, 2023, 05:54 PM
#15
Re: The certificate chain was issued by an authority that is not trusted
 Originally Posted by blakemckenna
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.

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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|