I have an ASP.Net MVC project that uses EF. I develop this application at work computer and at my home computer. The following is in my Web.config. How could I change the EDMX with the proper connection string for each office? So far, I have to drop the EDMXs and re-add them and comment out other connection strings. Thanks.
<connectionStrings>
<clear/>
<!-- At Home connections -->
<add name="App1Entities" connectionString="metadata=res://*/Models.App1Model.csdl|res://*/Models.App1Model.ssdl|res://*/Models.App1Model.msl;provider=System.Data.SqlClient;provider connection string="data source=my-pc\SqlExpress;initial catalog=App1Database;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="Service1Entities" connectionString="metadata=res://*/Models.Service1Model.csdl|res://*/Models.Service1Model.ssdl|res://*/Models.Service1Model.msl;provider=System.Data.SqlClient;provider connection string="data source=my-pc\SqlExpress;initial catalog=ServiceDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<!-- At Work connections
<add name="App1Entities" connectionString="metadata=res://*/Models.App1Model.csdl|res://*/Models.App1Model.ssdl|res://*/Models.App1Model.msl;provider=System.Data.SqlClient;provider connection string="data source=sqlServer1;initial catalog=App1Database;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="Service1Entities" connectionString="metadata=res://*/Models.Service1Model.csdl|res://*/Models.Service1Model.ssdl|res://*/Models.Service1Model.msl;provider=System.Data.SqlClient;provider connection string="data source=sqlServer2;initial catalog=ServiceDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
-->
</connectionStrings>
You need multiple connection strings, but you don't have to put a switch in your code; use
<connectionStrings configSource="MyLocalConnectionStrings.config" />
You'd need to maintain MyLocalConnectionStrings.config in the same dir as web.config, and have a different version for each development environment.