I am trying to change my asp.net mvc project from no authentification, to individual user account. I got to the point where I need to change my AdminDbContext to Application Db context.
I read that i need to put in the base the connection string of my mdf database, which i did, but then i got the error in the title. I tried removing the attachdbfilename but that did not work either because of the security integrated. After I deleted that one it told me that the path is invalid.
public class
{
public ApplicationDbContext()
: base("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Users\\Alex\\Desktop\\Licenta\\Licenta\\App_Data\\Database.mdf;Integrated Security
= True", throwIfV1Schema: false)
{
}
public DbSet<Food> Foods { get; set; }
public DbSet<User> Users { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
The exception that I get is from this code:
if (!roleManager.RoleExists("Administrator")) <---
{
// Se adauga rolul de administrator
var role = new IdentityRole();
role.Name = "Administrator";
roleManager.Create(role);
// se adauga utilizatorul administrator
var user = new ApplicationUser();
user.UserName = "[email protected]";
user.Email = "[email protected]";
var adminCreated = UserManager.Create(user, "Administrator1!");
if (adminCreated.Succeeded)
{
UserManager.AddToRole(user.Id, "Administrator");
}
}
It is different from this question: Keyword not supported: 'attachdbfilename' - MDF Database File (C#), because i dont use sqlce and removing the attachdbname still doesnt work as I have mentioned above.