title: Can't connect to Database to execute Identity functions
body: <p>I've created a new application with ASP.NET MVC5, using Individual User Accounts for security and Code-First Migrations for the Models/Database modeling. All options are default.</p>
  
  <p>I want to setup custom Users and Roles to it, so i created a Seed using <code>RoleManager</code> and <code>UserManager</code> just to populate the Database. It works fine, create 3 Users, 3 Roles and set each User's Role correctly.</p>
  
  <p>I can log in to the application correctly. The problem is that i can't execute any Identity method using the 
  <strong>User</strong>, which is the logged User, the only things that i can get is the <code>User.Identity.IsAuthenticated</code> value, and the <code>User.Identity.Name</code>, which are correct. Every other method like <code>Roles.GetRolesForUser("John")</code>, or <code>User.IsInRole("Student")</code>, always generates this exception:</p>
  
  <blockquote>
    <p>ProviderException : The Role Manager feature has not been enabled.</p>
  </blockquote>
  
  <p>So okay, as in <a href="https://stackoverflow.com/questions/3874279/the-role-manager-feature-has-not-been-enabled">this article</a>, i managed to insert the the <code>&lt;roleManager enabled="true" /&gt;</code> in the Web.config, and now it takes a <strong>really long time to respond</strong>, and generates Exceptions like:</p>
  
  <p>Referring to:
  </p>
  
  <pre><code>Roles.IsUserInRole("Student")
  </code></pre>
  
  <p>Generates:
  </p>
  
  <pre><code>HttpException
  </code></pre>
  
  <p>Referring to:
  </p>
  
  <pre><code>Roles.GetRolesForUser(User.Identity.Name)
  </code></pre>
  
  <p>Generates:
  </p>
  
  <pre><code>NullReferenceException
  </code></pre>
  
  <p>Accessing the About page with a User in Student role logged in:
  </p>
  
  <pre><code>[Authorize(Roles="Teacher")]
  public ActionResult About()
  {
      ViewBag.Message = "Your application description page.";
  
      return View();
  }
  </code></pre>
  
  <p>Generates:
  </p>
  
  <pre><code>SqlException
  HttpException
  </code></pre>
  
  <p>It's like i have no connection to the Database at all, which is LocalDB, automatically generated and i could populate in the Seed Method and even make Login to the application.</p>
  
  <p>I could even load data from the AspNetUsers table and show it in the View using the code below:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (Models.ApplicationDbContext db = new Models.ApplicationDbContext())
  {
      List&lt;Models.ApplicationUser&gt; Users = db.Users.ToList();
  
      ViewBag.Users = Users;
  }
  
  return View();
  </code></pre>
  
  <p><strong>PLEASE HELP :'(</strong></p>
  
  <hr>
  
  <p>Here's the Seed code, that works fine, so it can connect to the Database using the Identity engine.</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected override void Seed(LocalBDAuthTest.Models.ApplicationDbContext context)
  {
      #region Create Roles Student, Teacher e Administrator
  
      var RoleManager = new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(context));
  
      // Student
      if (!RoleManager.RoleExists("Student"))
      {
          RoleManager.Create(new IdentityRole("Student"));
      }
  
      // Teacher
      if (!RoleManager.RoleExists("Teacher"))
      {
          RoleManager.Create(new IdentityRole("Teacher"));
      }
  
      // Administrator
      if (!RoleManager.RoleExists("Administrator"))
      {
          RoleManager.Create(new IdentityRole("Administrator"));
      }
  
      #endregion
  
      #region Create Users for Student, Teacher e Administrator Roles.
  
      var UserManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(context));
  
  
      // Create a Student user and set it's role to Student
      if (!context.Users.Any(u =&gt; u.UserName == "John"))
      {
          var Student = new ApplicationUser() { UserName = "John" };
          var Result = UserManager.Create(Student, "123456");
      }
      if (!UserManager.FindByName("John").Roles.Any())
      {
          UserManager.AddToRole(UserManager.FindByName("John").Id, "Student");
      }
  
  
      // Create a Teacher user and set it's role to Teacher
      if (!context.Users.Any(u =&gt; u.UserName == "Arnold"))
      {
          var Teacher = new ApplicationUser() { UserName = "Arnold" };
          var Result = UserManager.Create(Teacher, "123456");
          UserManager.AddToRole(Teacher.Id, "Teacher");
      }
      if (!UserManager.FindByName("Arnold").Roles.Any())
      {
          UserManager.AddToRole(UserManager.FindByName("Arnold").Id, "Teacher");
      }
  
  
      // Create a Administrator user and set it's role to Administrator
      if (!context.Users.Any(u =&gt; u.UserName == "Caroline"))
      {
          var Administrator = new ApplicationUser() { UserName = "Caroline" };
          var Result = UserManager.Create(Administrator, "123456");
          UserManager.AddToRole(Administrator.Id, "Administrator");
      }
      if (!UserManager.FindByName("Caroline").Roles.Any())
      {
          UserManager.AddToRole(UserManager.FindByName("Caroline").Id, "Administrator");
      }
  
      #endregion
      }
  </code></pre>