Hi, I'm working on a school project - a fake online store. I've used some code from the MusicStore example on the Asp.Net website.
When I started working on the checkout controller, I encountered a problem. I keep getting this error when I try to login on the website with the user I'm seeding in my Initializer.
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll but was not handled in user code Additional information: Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed
The error points to this specific part of my _Layout.cshtml:
@if (User.IsInRole("Admin")) {<li>@Html.ActionLink("Categories", "Index", "Categories")</li> }
Any ideas of what it can be?
If you want to see my Initializer here it is:
public class DatabaseEfInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext> { protected override void Seed(ApplicationDbContext context) { //Kategorier context.Categories.Add(new Category {Name = "Bildskärmar"}); context.Categories.Add(new Category {Name = "Möss & Tangentbord"}); context.Categories.Add(new Category {Name = "Headset"}); context.Categories.Add(new Category {Name = "Ljud"}); context.Categories.Add(new Category {Name = "Surfplattor"}); context.Categories.Add(new Category {Name = "Mobiltelefoner"}); //Produkter context.Products.Add(new Product { Title = "MSI GE62 2QE-034NE", Category = new Category {Name = "Bärbara datorer"}, Price = 14999, Description ="MSI har konstruerat ett lättviktschassi med hjälp av inte bara traditionell aluminium, utan också en" +" Mg-Li-legering. Eftersom de mesta av chassit består av speciallegering, är det 44% styvare och 23% lättare än" +" ett chassi gjort av endast aluminium, samtidigt som det är den första datorn som någonsin använt den typen av stomme.", ProductImageUrl = "http://www.vatanbilgisayar.com/UPLOAD/PRODUCT/MSI/thumb/v2-73328-4_large.jpg" }); base.Seed(context); InitializeIdentityForEf(context); } public static void InitializeIdentityForEf(ApplicationDbContext db) { var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db)); var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db)); const string name = "mvc@projekt.se"; const string password = "Password@1"; const string roleName = "Admin"; //Create Role Admin if it does not exist var role = roleManager.FindByName(roleName); if (role == null) { role = new IdentityRole(roleName); var roleresult = roleManager.Create(role); } var user = userManager.FindByName(name); if (user == null) { user = new ApplicationUser { UserName = name, Email = name, }; var result = userManager.Create(user, password); result = userManager.SetLockoutEnabled(user.Id, false); } // Add user admin to Role Admin if not already added var rolesForUser = userManager.GetRoles(user.Id); if (!rolesForUser.Contains(role.Name)) { var result = userManager.AddToRole(user.Id, role.Name); } } }