1

I inherited an old vs.net 2010 WCF webservice project to make a fix to. It has the following connectionString settings in its web.config, to differentiate between dev, qa, & production & I'm having trouble connecting to them when trying to debug & hoping someone can help:

  <connectionStrings>    
     <add name="OrderDataContextContainer.Development" connectionString="metadata=res://<conn string here>" providerName="System.Data.EntityClient" />
     <add name="OrderDataContextContainer.QA" connectionString="metadata=res://<conn string here>" providerName="System.Data.EntityClient" />
     <add name="OrderDataContextContainer.Production" connectionString="metadata=res://<conn string here>" providerName="System.Data.EntityClient" /> 
 </connectionStrings>

The code I added, makes a db connection via the following "using" statement:

using (OrderDataContextContainer db = new OrderDataContextContainer())
 {
      //my code fix here
 }

If I add the following web.config connection to the list of connectionStrings, it connects fine (i.e. no "Development", "QA", or "Production" appended):

<add name="OrderDataContextContainer" connectionString="metadata=res://<conn string here>" providerName="System.Data.EntityClient" /> 

However, I can't do it like this because my company requires separate dev, qa, & prod strings for when I send this fix to the QA team for testing. If I don't include the above connection, I receive the following error on that "using" statement:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Before running the project, I created "Development", "QA", & "Production" configs in my vs.net Configuration Manager & set it to "Development" but no luck.

Any idea how I can get my application to connect via the earlier mentioned connection strings?

goalie35
  • 786
  • 3
  • 14
  • 34
  • maybe this [article](http://stackoverflow.com/questions/5811305/web-config-debug-release) can help you. you need to add web.QA.Config and web.Production.config. when you start publish, you can choose different profile(web.config), and then can transform your connection string. – kcwu Dec 30 '16 at 16:35
  • Transforms are the way to go, but another option is [connection string builder](http://stackoverflow.com/questions/19065361/making-entityframework-connection-string-dynamic) if you want to do it in code. – Steve Greene Dec 30 '16 at 16:37

1 Answers1

3

That's because EF always searches for the same connection string in the .config file. The name is defined in the EF designer and usually has the same name as the context class.

What you can do, is use web.config transformations, on how to do it in your project: How to: Transform Web.config When Deploying a Web Application Project

Itay Podhajcer
  • 2,616
  • 2
  • 9
  • 14