Actually, the title already summarizes my whole problem. I'm using Visual Studio 2017 and Entity Framework 6. In my MVC application, when I follow code-first approach, with default settings I was only given options of either LocalDB or SQL Server Express to use in the SQL Server Object Explorer. I am able to see corresponding tables for my models in action using SQL Express.
However, I want to use my SQL Server 2017. I guess I must specify my desired DB in connection string but I could not figure out how to do that with Entity Framework 6.
You can just open your project web.config
file, or the app.config
file, then update your entity framework connection string to refer to the SQL Server instance you need just like below:
<add name="DefaultConnection" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=YourServerInstance;Initial Catalog=YourDB;Persist Security Info=True;User ID=sa;Password=123456;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Make sure that you are editing the right connection string by checking your context class to check which connection string key name it refers:
public YourContext(bool lasyLoadingEnabled) : base("DefaultConnection")
{
Database.SetInitializer<NimasContext>(null);
this.Configuration.LazyLoadingEnabled = lasyLoadingEnabled;
this.Configuration.ProxyCreationEnabled = false; ;
}
You can follow this link: https://msdn.microsoft.com/en-us/library/jj556606(v=vs.113).aspx