title: Why can't my WCF Web Service see it's own web.config Connectionstrings?
body: <p>I have written an ASP.Net 3.5 WCF service and when I created this project VS gave me a web.config file to go with it. Having done this the app now seems entirely blind to connectionstrings, a big problem as the app will be heavily reliant on reformatting and spitting out SQL Server DB data in various web friendly formats.</p>
  
  <p>Most of the references I've seen for getting WCF services equipped with DB Connections tell you to put the connection strings in App.Config files, I was keen to avoid this... and so is VS2008, as when I try to add a new app.config a straight configuration file is not a choice on offer, only a second web configuration file.</p>
  
  <p>Seeing as I already have one perfectly good web.config file I would rather my data access code could just use that. I guess I'm probably missing something really obvious but:</p>
  
  <pre><code>ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString
  </code></pre>
  
  <p>Doesn't work as in debug the configurationmanager claims there are no connectionstrings defined, despite the fact that I have seven connectionstrings fully defined in the web.config file. I have using statements for System.Configuration, System.Web and System.Web.Configuration.</p>
  
  <p>It seems as if even though the project seems to be designed to refer to a web.config this is not in fact the case. It also seems to be unable to access a regular app.config at present.</p>
  
  <p>Having said all this all the httphandlers and endpoints in the web.config seem fine. If I define the connectionstring specifically when I call the datacontext it all works perfectly. It's specifically the connectionstring section of the config file that seems to be having an issue...</p>
  
  <p>Any thoughts?</p>
  
  <p>EDIT:</p>
  
  <p>FWIW this is the (only slightly doctored) content of the ConnectionStrings section of the web.config.</p>
  
  <pre><code>&lt;connectionStrings&gt;
          &lt;add name="D_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="PV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="L_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="AL_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="APV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="AD_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
          &lt;add name="TV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/&gt;
      &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Like I said anything else the file is supposed to do to assist in the execution of its duties it appears to do without issue or complaint.</p>
  
  <p>FURTHER EDIT: The application is currently only in development, so is attempting to run through the VSHOST it will in the fulness of time be hosted on the web through IIS.</p>
  
  <p>And yes, I have an explicit project reference to System.Configuration</p>
  
  <p>UPDATE: To try to lock this down I had a go at passing the ConnectionString as a string from an AppSetting, as so far I have been using</p>
  
  <pre><code>DataServiceContext dsc  = new DataServiceContext("connection string as string");
  </code></pre>
  
  <p>It can't see the AppSettings either.</p>