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.
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.
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:
ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString
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.
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.
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...
Any thoughts?
EDIT:
FWIW this is the (only slightly doctored) content of the ConnectionStrings section of the web.config.
<connectionStrings>
<add name="D_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="PV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="L_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="AL_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="APV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="AD_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
<add name="TV_CS" connectionString="[the_connection_string]" providerName="System.Data.SqlClient"/>
</connectionStrings>
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.
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.
And yes, I have an explicit project reference to System.Configuration
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
DataServiceContext dsc = new DataServiceContext("connection string as string");
It can't see the AppSettings either.