Search code examples
asp.net-mvc-5asp.net-identity

How to change database from Local to Host to use Identity model


I have a databse that located to App_Data folder with below connection string:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-mydb-20171102055914.mdf;Initial Catalog=aspnet-mydb-20171102055914;Integrated Security=True"
  providerName="System.Data.SqlClient" /> 


I've used it for Asp Identity User Manager Model.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

but I want to use the database that is located in server. my server connection string structure is something like :

<add name="DefaultConnection" connectionString="metadata=res://*/Models.Database.mydbModel.csdl|res://*/Models.Database.mydbModel.ssdl|res://*/Models.Database.mydbModel.msl;provider=System.Data.SqlClient;provider connection string='data source=134.54.96.45,1355;initial catalog=Db_Server;user id=&quot;serverUser&quot;;password=serverPass;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />


the server connection string works correctly for other models. but when I want to use ASP Identity Model, its caused error. How I cant fix it?


Solution

  • I fixed this by creating a standard connection string that pointed to the database where the ASP.NET Identity tables are.

    <add name="DefaultConnection" connectionString="Data Source=134.54.96.45,1355; Initial Catalog=Db_Server; User ID=&quot;serverUser&quot;; Password=serverPass; Connect Timeout=60;" providerName="System.Data.SqlClient" />
    

    I do not know why the Identity Model just worked with this connection string and what is the diffrent between these connction strings.
    but this last works correctly for me.