locked
MVC 5 Database First Connection String Conflict RRS feed

  • Question

  • User-1034524349 posted

    Hi all,

    I have an MVC 5, Database First application with individual User Accounts but the only way I can get it to work is with two connection strings, one for Authentication and one for the rest of the database i.e.. Entities.

    String one for Authentication:

    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=True" providerName="System.Data.SqlClient" />
    

    and then in IdentityModels.cs

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }
    
        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

    String Two for the rest of the database:

    <add name="appEntities" connectionString="metadata=res://*/Models.databasename.csdl|res://*/Models.databasename.ssdl|res://*/Models.databasename.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLExpress;initial catalog=databasename;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

    The problem is if I change base("DefaultConnection", throwIfV1Schema: false) to base("appEntities", throwIfV1Schema: false) in ApplicationDbContext and remove string one I get an error when I try to login and if I leave it as is above and remove string two, I can login but the rest of the app doesn't work because it's cannot load the metadata.

    So Authentication does not want to know about metadata but appEntities needs it.

    Any ideas.

    Cheers,

    Mike.

    Monday, May 18, 2015 12:14 AM

Answers