17

When I run dotnet ef update database I get this error:

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.)

my csproj file:

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-preview.5.22302.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.5.22302.2">
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-preview.5.22302.2" />
  </ItemGroup>

my connection string:

"DefaultConnectionString": "Server=.;Database=ShopCore;Trusted_Connection=True;"
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Amirabbas Motamedi
  • 321
  • 1
  • 2
  • 9
  • 24
    Try to add `;TrustServerCertificate=True` to connection string, – Svyatoslav Danyliv Jul 07 '22 at 10:25
  • Your machine doesn't trust the SSL certificate used by the server, probably because it's self-signed. Either give it a proper certificate from a private or public CA that your machine trusts, or use `TrustServerCertificate=True` in the connection string. I advise the former, and *not* the latter, it essentially means you have no security at all. – Charlieface Jul 07 '22 at 10:25
  • Does this answer your question? ["The certificate chain was issued by an authority that is not trusted" when connecting DB in VM Role from Azure website](https://stackoverflow.com/questions/17615260/the-certificate-chain-was-issued-by-an-authority-that-is-not-trusted-when-conn) – Charlieface Jul 07 '22 at 10:26

5 Answers5

20
"Data Source=DESKTOP-R34I8VP;Initial Catalog=LINQ;Integrated Security=True;TrustServerCertificate=True"

Or

"Server=DESKTOP-R34I8VP;Database=Linq;Trusted_Connection=True;TrustServerCertificate=True;"
Ragab Mohamad
  • 371
  • 2
  • 4
17

Add encrypt=false; to your connection string. If you're using Azure SQL though, I think an encrypted connection is required.

Bill Sambrone
  • 4,334
  • 4
  • 48
  • 70
0

So I figured out that I should use EntityFrameworkCore.SqlServer version 6.0.6 instead of 7.0.0-preview.5.22302.2

Amirabbas Motamedi
  • 321
  • 1
  • 2
  • 9
  • 3
    I'm guessing this is related to the breaking change that it defaults to encryption on https://techcommunity.microsoft.com/t5/sql-server-blog/released-general-availability-of-microsoft-data-sqlclient-4-0/ba-p/2983346 – Charlieface Jul 07 '22 at 13:04
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 09 '22 at 14:08
0

I use
Microsoft.EntityFrameworkCore 7.0.4 +
Microsoft.EntityFrameworkCore.SqlServer 7.0.4 +

Inside

public void ConfigureServices(IServiceCollection services)

I inserted

connectionString + ";TrustServerCertificate=true;"


obvious where connection string is your connection string like below
 services.AddDbContext<DbContext>(options =>
                {
                    options.UseSqlServer("connectionString" + ";TrustServerCertificate=true;");
                    options.EnableSensitiveDataLogging();
                    options.EnableDetailedErrors();
                }
                ) ;
-1

There are three possible solutions by Microsoft:

Solution 1: Use Microsoft OLE DB Driver for SQL Server 18.x. You can download the driver from Release notes for the Microsoft OLE DB Driver for SQL Server.

Solution 2: If the application connection string property already specifies a value of Yes or Mandatory for the Encrypt/Use Encryption for Data setting, change the value to No or Optional. For example, Use Encryption for Data=Optional. If the connection string doesn't specify any value for Encrypt/Use Encryption for Data, add Use Encryption for Data=Optional to the connection string. For more information, see Encryption and certificate validation.

Solution 3: Add ;Trust Server Certificate=true to the connection string. This will force the client to trust the certificate without validation.

I used the third one for my local db and it worked for me.

https://learn.microsoft.com/en-us/troubleshoot/sql/database-engine/connect/certificate-chain-not-trusted?tabs=ole-db-driver-19