-1

My company uses different databases depending on which stage of development a project is in. Currently I'm trying to push for adoption of Entity Framework + LINQ but have hit a stumbling block when asked how this would work across our multiple environments.

They are under the impression it will have to be manually changed for each environment and will thus take forever to deploy.

How do I configure EF Database-First to use a different connection on dev, test, and production servers?

Can I set some sort of variable? Is there an option I missed?

jonjw
  • 21
  • 1
  • 2
  • `They are under the impression it will have to be manually changed`. More or less true. You can have multiple build configurations and create an app.config/web.config file (with different connection strings) for each (see config transformations), or put the connection strings in a different file. – gunr2171 Jun 09 '14 at 20:58
  • 2
    duplicate of http://stackoverflow.com/questions/1406157/differentiating-web-config-between-dev-staging-and-production-environments, http://stackoverflow.com/questions/305447/using-different-web-config-in-development-and-production-environment, http://stackoverflow.com/questions/544096/different-configuration-files-for-development-and-production-in-asp-net-applicat, http://stackoverflow.com/questions/592672/how-do-you-handle-multiple-web-config-files-for-multiple-environments – Justin Helgerson Jun 09 '14 at 21:02
  • Welcome to Stack Overflow! Please search SO for duplicate questions before you ask a new one. If the above user could find 4 duplicates in seven minutes, that indicates a lack of research effort. – eddie_cat Jun 09 '14 at 21:19

2 Answers2

0

EDIT: Possible duplicate of Managing a Debug and Release Connection String

You can specify the connection string that your application uses using an app.config or web.config file, depending on the type of project you're using.

Read this great documentation: http://msdn.microsoft.com/en-us/data/jj592674

For a database-first application using EF, here's a sample app.config:

<configuration>  
  <connectionStrings>  
    <add name="Northwind_Entities"  
         connectionString="metadata=res://*/Northwind.csdl|  
                                    res://*/Northwind.ssdl|  
                                    res://*/Northwind.msl;  
                           provider=System.Data.SqlClient;  
                           provider connection string=  
                               &quot;Data Source=.\sqlexpress;  
                                     Initial Catalog=Northwind;  
                                     Integrated Security=True;  
                                     MultipleActiveResultSets=True&quot;"  
         providerName="System.Data.EntityClient"/>  
  </connectionStrings>  
</configuration>

You can use a different app.config during debug and release (here's instructions http://mitasoft.wordpress.com/2011/09/28/multipleappconfig/), which makes it really easy for EF to pick up a different config in different environments.

Community
  • 1
  • 1
Ryan Erdmann
  • 1,786
  • 10
  • 11
  • I'd really hope that the connection strings were in the web.config/app.config file to begin with. – gunr2171 Jun 09 '14 at 21:00
  • Thank you for the links you provided, very useful for me! You got a +1 from me! Don't know who downvoted this previously, but IMHO the answer deserves more upvotes! – Matt Dec 04 '14 at 12:05
0

Depending on your .net version, you can use web.config.debug, and web.config.release

Here is a related SO question with more information

Community
  • 1
  • 1
Smeegs
  • 9,151
  • 5
  • 42
  • 78