Entity framework Asp.Net核心创建数据库
我使用的是.net核心技术,在创建新数据库时遇到了一些错误 这是我的NorthwindContext类,我在这里编写服务器位置Entity framework Asp.Net核心创建数据库,entity-framework,asp.net-core-mvc,Entity Framework,Asp.net Core Mvc,我使用的是.net核心技术,在创建新数据库时遇到了一些错误 这是我的NorthwindContext类,我在这里编写服务器位置 public class NorthwindContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(@
public class NorthwindContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Northwind;Persist Security Info=True; User ID=sa; Password=xxxxxxxx");
}
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
}
结果,我得到了以下结果:
Microsoft.EntityFrameworkCore.dll中发生类型为“System.Data.SqlClient.SqlException”的未处理异常
其他信息:用户“sa”登录失败
我正在等待您的帮助,提前谢谢。错误消息确实包含了足够的信息 用户“sa”登录失败 将ConnectionStating与trustedconnection一起使用,而不是用户名和密码 它看起来像:
connectionString="Server=(localdb)\mssqllocaldb;Database=Northwind;Trusted_Connection=True;"
connectionString="Server=(localdb)\mssqllocaldb;Database=Northwind;Trusted_Connection=True;"