当证书链由不受信任的机构颁发时,如何使脚手架在.net 7.0中工作?



为什么脚手架时我得到证书不受信任?

我正在运行EF Tools Scaffold-DbContext命令并得到以下错误:

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

下面是我发出的命令:

Scaffold-DbContext "Server=SQL.mysite.com;Initial Catalog=db_data;User Id=db_admin;Password=pass123;Persist Security Info=True;Encrypt=true/yes" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "MyDataDbContext" -DataAnnotations -Force

你能告诉我如何解决这个问题吗?

这里重要的部分是指定您信任服务器证书。只需在连接字符串中包含以下内容:

TrustServerCertificate=True

这是我在Visual Studio 2022和。net 7.0上的工作:

Scaffold-DbContext "Server=SQL.mysite.com;Initial Catalog=db_data;User Id=db_admin;Password=pass123;Persist Security Info=True;Encrypt=true;TrustServerCertificate=yes" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "MyDataDbContext" -DataAnnotations -Force

相关内容

  • 没有找到相关文章

最新更新