0

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>
Hysteria86
  • 367
  • 1
  • 10
  • http://stackoverflow.com/questions/1339944/cant-connect-to-localhost-but-can-with-computer-name-in-sql-server-2008 – Mehmet Jun 30 '16 at 08:36
  • Not sure this answers the question. I have it working fine in my local/SQLExpress environment. I want to know how I need to adapt my connection string details for a hosted SQL database in a production environment. – Hysteria86 Jun 30 '16 at 10:04

1 Answers1

1

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.

Mehmet
  • 739
  • 1
  • 6
  • 17