title: MVC 4 change membership database
body: <p>I created an mvc 4 application code first application, the membership tables aren't being stored on the .\SQLEXPRESS database, I changed the name of the connection string name to my dbcontext which is EntitySets and also changed the InitializeMembershipAttribute class with the EntitySet context but they still aren't being stored? Thanks for the help!!</p>
  
  <p>DbContext</p>
  
  <pre><code> public class EntitySets: DbContext
  {
      public DbSet&lt;User&gt; Users { get; set; }
      public DbSet&lt;UserStats&gt; UserStats {get;set;}
      public DbSet&lt;UserProfile&gt; UserProfiles { get; set; }
  }
  </code></pre>
  
  <p>AccountModel</p>
  
  <pre><code>public class UsersContext : DbContext
  {
      public UsersContext()
      : base("EntitySets")
      {
      }
  
      public DbSet&lt;UserProfile&gt; UserProfiles { get; set; }
  }
  </code></pre>
  
  <p>InitializeMembership</p>
  
  <pre><code> public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
  {
      private static SimpleMembershipInitializer _initializer;
      private static object _initializerLock = new object();
      private static bool _isInitialized;
  
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          // Ensure ASP.NET Simple Membership is initialized only once per app start
          LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
      }
  
      private class SimpleMembershipInitializer
      {
          public SimpleMembershipInitializer()
          {
              Database.SetInitializer&lt;EntitySets&gt;(null);
  
              try
              {
                  using (var context = new EntitySets())
                  {
                      if (!context.Database.Exists())
                      {
                          // Create the SimpleMembership database without Entity Framework migration schema
                          ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                      }
                  }
  
                  WebSecurity.InitializeDatabaseConnection("EntitySets", "UserProfile", "UserId", "UserName", autoCreateTables: true);
              }
              catch (Exception ex)
              {
                  throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
              }
          }
      }
  </code></pre>
  
  <p>Connection String</p>
  
  <pre><code> &lt;add name="EntitySets"  connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Fitness_Friend.Web.Models.EntitySets;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>