赞
踩
报错内容:A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)
数据库版本:SQL Server2014
visualstudio版本:2022
数据库创建采用模型驱动
写好eitity类,在配置DbContext时,代码如下:
```csharp using Microsoft.EntityFrameworkCore; namespace ShuDaKang.Entity { /// <summary> /// 用于建立实体类和 数据库表连接上下文 /// </summary> public class MyDbContext : DbContext { public DbSet<Activity> Activitys { get; set; } //对应Activity实体类 //重写 对要链接的数据库进行配置 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { //数据库地址 string connStr = "Server=.;Database=shudakang;User=Administrator ;Password= ;Trusted_Connection=True;MultipleActiveResultSets=true"; optionsBuilder.UseSqlServer(connStr); } //重写 模型创建 指定程序集 protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); //加载 当前程序集中所有实现了IEntityTypeConfiguration接口的类 modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly); } } }
创建Migration
Add-Migration CreateActivityModel
迁移数据库
Update Migration
报错:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)
机翻:已成功与服务器建立连接,但在登录过程中发生错误。(提供程序:SSL提供程序,错误:0-证书链是由不受信任的颁发机构颁发的。)
这是数据库连接字符串的问题,但是安装sqlServer2014时采用windows验证身份验证(我Windows10 系统时没有设置登录密码的)或者SQL Server身份验证。
连接字符串改成如下:
string connStr = "Server=.;Database=shudakang;Encrypt=True;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true";
添加了Encrypt=True;Trusted_Connection=True;TrustServerCertificate=True;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。