简体   繁体   中英

Pointing a Code First Entity Framework to a created database

I am creating a Code First Entity Framework to create a database to where I point it to. I have an instance of SQL => DESKTOP-98TG6JE\\SQLEXPRESS and another one => DESKTOP-98TG6JE

In my Asp MVC code, my connection string is like so in the Web.config

<connectionStrings>
    <add name="MusicStoreDB" connectionString="Data Source=DESKTOP-98TG6JE;Initial Catalog=MusicStoreDB;User ID=sa;Password=myPassword123" providerName="System.Data.SqlClient" />
</connectionStrings>

and in my MusicStoreDB : DbContext ,

public MusicStoreDB() : base("MusicStoreDB")
{
}

But when I run the program, it creates a database in the DESKTOP-98TG6JE\\SQLEXPRESS named DefaultConnection and on the instance where I want to create the database, no MusicStoreDB database is created. Image of the created database on the wrong instance

Can you please explain it to me why this is happening? Thank you.

Check you connection string name provided in ApplicationDbContext :

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("MusicStoreDB")
    {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM