dotnet ef update database : 已成功与服务器建立连接,但在登录过程中发生错误

Ami*_*edi 23 sql-server sqlclient entity-framework-core ef-core-7.0

当我运行 dotnet ef update 数据库时出现此错误:

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.)
Run Code Online (Sandbox Code Playgroud)

我的 csproj 文件:

  <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>
Run Code Online (Sandbox Code Playgroud)

我的连接字符串:

"DefaultConnectionString": "Server=.;Database=ShopCore;Trusted_Connection=True;"
Run Code Online (Sandbox Code Playgroud)

小智 31

"Data Source=DESKTOP-R34I8VP;Initial Catalog=LINQ;Integrated Security=True;TrustServerCertificate=True"
Run Code Online (Sandbox Code Playgroud)

或者

"Server=DESKTOP-R34I8VP;Database=Linq;Trusted_Connection=True;TrustServerCertificate=True;"
Run Code Online (Sandbox Code Playgroud)


Bil*_*one 20

添加encrypt=false;到您的连接字符串。如果您使用的是 Azure SQL,我认为需要加密连接。


Ami*_*edi 0

所以我发现我应该EntityFrameworkCore.SqlServer version 6.0.6 instead使用7.0.0-preview.5.22302.2

  • 我猜这与 https://techcommunity.microsoft.com/t5/sql-server-blog/released-general-availability-of-microsoft-data-sqlclient-4 上默认加密的重大更改有关-0/ba-p/2983346 (3认同)