0

I have a WCF service which references a Data access library. In the data access library there is an app.config file containing a connection string to the database. Rather than recompiling the referenced data access library every time I would like to change the connection string. I would like to be able to put the connection string into the app.config file of the wcf project. Is this possible? and if so how?

JKennedy
  • 18,150
  • 17
  • 114
  • 198

1 Answers1

3

Your data access library shouldn't have an app.config because it's not an application.

The whole point of using app.config is to allow each individual application to configure itself, using settings that libraries respect.

This is especially easy for things like connection strings. Just put the connection string into the app.config file for the WCF service. All you need to do in the data access library is make sure it knows which connection string name it should be trying to use.

Yuck
  • 49,664
  • 13
  • 105
  • 135
  • I'm not sure I understand how I would do that. Would I be using ConfigurationManager in my data access library to read the ConnectionString from the WCF app.config at runtime? – JKennedy Jun 17 '14 at 11:53
  • Yes, that is exactly how you'd access the `ConnectionStrings` property. http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx – Yuck Jun 17 '14 at 12:12