efcore: EFCore.SqlServer 6.0.1 Untrusted certificate authority error

Why is ef core trying to use ssl encrypted connection to connect to database when switching from 6.0.0 to 6.0.1?

When we update EntityFrameworkCore.SqlServer from Version 6.0.0 to Version 6.0.1 we cannot connect to our database anymore because of an untrusted certificate authority error. It also happens when we try Scaffolding. ConnectionString: Data Source=localhost;Initial Catalog=local-Sales;Persist Security Info=True;User ID=sa;Password=sa-local-2019;

StackTrace:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

When I add trustServerCertificate=true to the connection string it works again: Data Source=localhost;Initial Catalog=local-Sales;Persist Security Info=True;User ID=sa;Password=sa-local-2019;trustServerCertificate=true Did you made this change on purpose? I cannot find anything about this change in the documents.

EF Core version: 6.0.1 Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0) Operating system: Windows 10 IDE: Jetbrains Rider 2021.3.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 21 (6 by maintainers)

Most upvoted comments

@ErikEJ adding trustServerCertificate=true does fix it.

Is there an issue adding that in?

SqlClient dependency down to 2.1 Published v6.2.8

EFCore.Bulkextensions explicitly depends on SqlClient 4.0. It should not do that, that is why you are facing breaking changes.

I would ask the author to stop doing that, and just use the 2.1 version the EF Core SqlServer package depends on instead. @borisdj

Hi there!

Just faced this issue too - we could no longer make new migrations and/or connect to local DBs, as this error then appeared. I saw you asked earlier for a csproj file, here’s ours:

`<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Optional" Version="4.0.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
    <ProjectReference Include="..\HoodHeroes.Widgets.Data\HoodHeroes.Widgets.Data.csproj" />
</ItemGroup>
</Project> `

and

`<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="EFCore.BulkExtensions" Version="6.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
  <ProjectReference Include="..\HoodHeroes.Common.Data\HoodHeroes.Common.Data.csproj" />
  </ItemGroup>

</Project>`

I believe that’s all of the relevant ones. Hope it helps, and thanks for the work on EF Core - SQL would have been a pain without 😃

I suspect its EFCore BulkExtensions here that refers o that, since the other packages are at 6.0.0 and not 6.0.1, as others pointed out was where the issue was introduced for them…

NB. Adding “trustServerCertificate=true” to our connection strings fixed our issues with not being able to connect to our DBs, when running our micro services locally 😃 Thanks for that tip!