Search code examples
entity-frameworkmodel-view-controllerconnection-stringlocaldb

MVC Connection Strings/LocalDb


Fairly new to MVC so this probably seems like a fairly newbie question.

I've been developing my application using a SQLExpress instance/LocalDb, I'm now ready to deploy my site to production, so my question is how do I configure my web.config file for this environment?

My database has been created in production, I'm just struggling with establishing the connection strings.

I'm using a host that I think does not support LocalDB (GearHost), but sources seem to suggest this is possible (even though I've not found any decent examples).

My current development connection strings are below.

Thanks

  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MyApp-20160204160648;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MyApp-20160204160648.mdf" />
    <add name="MyEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MyPC\SQLEXPRESS;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>

Solution

  • I have a MVC project.I use two conectionString as following

    <add name="matematikEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=MYSERVERNAMEONHOST;user id=MYUSERID;password=MYPASSWORD;persistsecurityinfo=True;database=MYDBNAME&quot;" providerName="System.Data.EntityClient" />  
    <add name="matematikEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;password=MYPASSWORD;persistsecurityinfo=True;database=MYDBNAME&quot;" providerName="System.Data.EntityClient" />  
    

    When i publish the project,i comment first one and second is active,when i work on my PC i comment second and first one is active.This works.