我正在尝试创建身份迁移 ASP.NET Core 2.0并收到错误。
System.Data.SqlClient.SqlException (0x80131904):无法打开登录请求的数据库"MarketIdentity"。登录失败。
Appsettings.json
"MarketIdentity": {
"ConnectionString": "Server=(localdb)\mssqllocaldb;Database=MarketIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}
启动.cs
public void ConfigureServices(IServiceCollection services)
{
//services.Configure<AppSettings>(Configuration.GetSection("Data:Market"));
services.AddMvc();
//app database
services.AddDbContext<EfDbContext>(
options => options.UseSqlServer(Configuration["Data:Market:ConnectionString"],
b => b.MigrationsAssembly("Market")));
//identity database
services.AddDbContext<AppIdentityDbContext>(
options => options.UseSqlServer(Configuration["Data:MarketIdentity:ConnectionString"],
b => b.MigrationsAssembly("Market")));
services.AddIdentity<IdentityUser, IdentityRole>(options => {
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
options.Password.RequireDigit = false;
})
.AddEntityFrameworkStores<AppIdentityDbContext>();
}
试试这个
"ConnectionStrings": {
"MarkIdentity": "Server=(localdb)\mssqllocaldb;Database=MarketIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}
services.AddDbContext<EfDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MarkIdentity")));