Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a question regarding web services and configuration files.

Platform:
.Net Framework , code behind c#.

Scenario:
I have a web service which when i publish, creates a bin folder. All normal. Now, in that bin folder i have a dll which is effectively my data access layer, CRUD for databases etc. Now i use ConfigurationManager.GetSection("AppConfig") within this dll in order to get database connection strings, which the dll brings out from the web service web.config file.

File Structure:

<My Web Service Folder>
--><AppData>
--><bin>
--><My Data Access Layer DLL>
--><web.config(includes data access layer variables)>

Within my development environment, this works like a charm, using ConfigurationManager.GetSection("AppConfig") from my dll to get out the appconfig section from my web.config and then searching the nodes in order to find the right key.

Example of web.config:

<AppConfig>
<Configs use="true">
<add key="Databases" use="true" />
</Configs>

<!-- Web Service Configuration Settings-->
<Databases>
<ConnectionStrings>
<add key="<MY KEY NAME>" providerName="System.Data.SqlClient"
value="<MY CONNECTION STRING>" />
</ConnectionStrings>
</Databases>
</AppConfig>

So far so good.

Now i am testing a deployment of this system on a virtual pc. I copy and paste the c:\initpub\<mywebservice> folder into the c:\inetpub of the virtual pc. I try and run it and it fails.

After inserting debugging into the code to see where it is failing, I find that ConfigurationManager.GetSection("AppConfig") is actually returning null instead of the appconfig section from the web.config. Does anybody know why this is happening ?

Please excuse the length of the post but was needed to explain the situation.

James
Posted
Updated 3-Mar-10 0:49am
v5

Instead of accessing the section and trying to parse the connection sting from that section, can you please try:

string connString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;


Meanwhile you can also check what you see in 'Event Viewer' for if there was an error. (Like access permission or tag not found or anything else)
 
Share this answer
 
v2
the thing is that i have created a custom class to handle the configuration and need to access it as stated. I could send you the code files if you want, but there are about 5 files
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900