【发布时间】:2016-09-18 18:57:57
【问题描述】:
我一直在使用 ASP.NET 5 RC1,其中我有一个应用程序,我在其中使用服务将管理凭据播种到数据库中,如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<AdministratorUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddTransient<AdministratorSeedData>();
}
这里是连接字符串子对象:
"ConnectionString": "Server=.;Database=kjanshair;Trusted_Connection=True;"
我用来播种数据的服务正在使用管理播种数据播种。一切正常,但是当我将其移植到 RC2 时,启动时发生以下更改:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddTransient<AdministratorSeedData>();
}
连接字符串为:
"ConnectionString": "Server=.;Database=_CHANGE_ME;Trusted_Connection=True;"
我在 Configure() 方法中遇到异常
public async void Configure(IApplicationBuilder app, AdministratorSeedData seeder)
{
app.UseIdentity();
app.UseMvcWithDefaultRoute();
await seeder.EnsureSeedData(); //Here exception occurs
}
说:
Message = "Cannot open database \"_CHANGE_ME\" requested by the login. The login failed.\r\nLogin failed for user 'DESKTOP-55E4D9H\\Janshair Khan'."
为什么会出现此错误?我已经查看了所有替代方案,但无法解决。
【问题讨论】:
-
查看 Julie lerman“数据农场”的最新帖子。可能会帮助你
标签: sql-server asp.net-core asp.net-identity entity-framework-core