• provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的
  • 发布于 2个月前
  • 1390 热度
    0 评论
我在用Scaffold-DbContext命令生成数据库表实体时,系统报错:Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)
 ---> System.ComponentModel.Win32Exception (0x80090325): 证书链是由不受信任的颁发机构颁发的。
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

   at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)


解决方法:连接数据库的字符串加Encrypt=True;TrustServerCertificate=True;即可,类似如下:

Scaffold-DbContext -Force “Server=ddm\SQLSERVER2019;Database=Com.ABC.StudentERP;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;” -Provider “Microsoft.EntityFrameworkCore.SqlServer” -OutputDir Models -Context BusinessTripData




用户评论