none
ASP.NET Identity Framework tries to create table even without migrations enabled RRS feed

  • Question

  • I have created an MVC site on my client which uses ASPNET Identity with EF.  It also uses another EF model with my business objects.  Both models use the same database. I am now trying to deploy the application to my webserver which uses the same database as I used on my client machine. The server application, however, is attempting to create new Identity tables and I get the error:  CREATE TABLE permission denied in database .  

    I checked the profiler of the database and there error occurs when the application is trying to create aspnetroles table.

    I have added the following both to my global.asax page:

     public class MvcApplication : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                Database.SetInitializer<BSRModel>(null);
                Database.SetInitializer<ApplicationDbContext>(null);
                Database.SetInitializer<IdentityDbContext>(null);
            }
        }

    And my applicationdbcontext page

      public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
        {
            public ApplicationDbContext()
                : base("DefaultConnection")
            {        }
            public ApplicationDbContext(string connectionStringName)
                : base(connectionStringName)
            {        }
            static ApplicationDbContext()
            {
                Database.SetInitializer<ApplicationDbContext>(null);
            }
            public static ApplicationDbContext Create()
            {
                return new ApplicationDbContext();
            }
        }
    }
    What am I missing?  Why is it creating tables on the production server and not on my machine when both are pointing to the exact same connection string?

     
    Monday, June 15, 2015 9:10 AM

Answers

  • I found the problem.  I neglected to grant permissions for the user to the Identity tables.  Apparently when EF was denied permission to the tables it assumed they didn't exist and tried to create them.  As soon as I granted permission to read the tables to the iis user, then EF did not try to create the table.

    • Marked as answer by hik Monday, June 15, 2015 11:57 AM
    Monday, June 15, 2015 11:57 AM

All replies

  • I found the problem.  I neglected to grant permissions for the user to the Identity tables.  Apparently when EF was denied permission to the tables it assumed they didn't exist and tried to create them.  As soon as I granted permission to read the tables to the iis user, then EF did not try to create the table.

    • Marked as answer by hik Monday, June 15, 2015 11:57 AM
    Monday, June 15, 2015 11:57 AM
  • Hello hik,

    It is glad to hear that you got it working and thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 16, 2015 1:41 AM
    Moderator