I've been using ASP.NET 5 RC1 in which I've an application in which I seed administrative credentials into the data base using Services as follows:
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>();
}
Here is the connection string sub-object:
"ConnectionString": "Server=.;Database=kjanshair;Trusted_Connection=True;"
And the service that I use to seed data is being seeded using the Administrative seed data. It all works fine but when I port it to RC2, with the following changes in the startup as:
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>();
}
with the connection string as:
"ConnectionString": "Server=.;Database=_CHANGE_ME;Trusted_Connection=True;"
I get an exception in Configure() method
public async void Configure(IApplicationBuilder app, AdministratorSeedData seeder)
{
app.UseIdentity();
app.UseMvcWithDefaultRoute();
await seeder.EnsureSeedData(); //Here exception occurs
}
saying as:
Message = "Cannot open database \"_CHANGE_ME\" requested by the login. The login failed.\r\nLogin failed for user 'DESKTOP-55E4D9H\\Janshair Khan'."
Why Am I getting this error? I've looked all over the alternatives but couldn't resolved.
I've identified the problem and now eventually solved it. The problem was the change in the Identity ecosystem of RC2. I added the migrations using by typing in the terminal as:
dotnet ef migrations add "migration message"
, update the database
dotnet ef database update
and now I'm able to seed the data in my database.