简体   繁体   中英

Suppress security on localhost connection between Microsoft SQLServer VisualStudio 2022

I got the following message

Microsoft.Data.SqlClient.SqlException HResult=0x80131904 Message=A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate c hain was issued by an authority that is not trusted.) Source=Core Microsoft SqlClient Data Provider

when establishing a connection to my local Microsoft SQL Server

My connection string is defined in appsettings.json

{
    "ConnectionStrings": {
        "DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=QandA;Trusted_Connection=True;",
    },
   "Logging": {
      "LogLevel": {
         "Default": "Information",
         "Microsoft.AspNetCore": "Warning"
      }
   },
   "AllowedHosts": "*"
}

in Program.cs, the following code that use DbUp work

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); 
EnsureDatabase.For.SqlDatabase(connectionString);
var upgrader = DeployChanges.To
    .SqlDatabase(connectionString, null)
    .WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
    .WithTransaction()
    .Build();

The API code call the following function

   /// <summary>
   /// Fetch toutes les questions de la BD.
   /// </summary>
   /// <returns>Les questions de la BD.</returns>
   public IEnumerable<QuestionGetManyResponse> GetQuestions()
   {
        // Le using va disposer de la connection automatiquement en quittant le block.
        using (var connection = new SqlConnection(_connectionString))
            {
               connection.Open();
               return connection.Query<QuestionGetManyResponse>(@"EXEC dbo.Question_GetMany");
            }
   }

The _connectionString variable is set in the class constructor. It is properly set when connection.Open() is executed.

How could I remove the security on that connection and why is it working in Program.cs

See comment on my post from Always Learning, I add encrypt=false in the connection string. That solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM