-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?

3
  • 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. Commented Jun 9, 2014 at 20:58
  • 2
  • 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. Commented Jun 9, 2014 at 21:19

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'd really hope that the connection strings were in the web.config/app.config file to begin with.
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!
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.