views:

4918

answers:

4

In my ASP.NET application I have a web.config file. In the web.config file I have a connection string...

<connectionStrings>
    <add name="HRDb" connectionString="xxxxx" providerName="System.Data.SqlClient" />
</connectionStrings>

Yet, when I retrieve this value using ConfigurationManager.ConnectionStringsp["HRDb"], I get the my old connection string, not the new one.

Where else (apart from web.config) does the ConfigurationManager read connection string values from?

I'm running the application from VS.NET (not deployed to IIS).

A: 

Where was the 'old' value stored? Is it in a different config file? The config manager should only pull from the config files, but there can be multiple files for an application. Is part of your build process copying in an old file?

Glenn Slaven
The old value was stored in the web.config file as well. Very strange. I don't have any build events. I only have one web.config, so all pretty straight-forward.If the ConfigurationManager only reads from web.config, then it must be a bug on my side. I'll see what I can find...
willem
+1  A: 

It is also possible, although unlikely, that you have a connection string defined in a "parent" web.config in a folder above your current folder or even in machine.config. Try to add a <clear /> element before the <add> element.

Rune Grimstad
+2  A: 

I figured out what was going wrong.

So to answer my own question... ConfigurationManager only reads from web.config.

My problem was that the project was configured to use an IIS web server when running the project instead of using the Visual Studio Development server. So I was in fact running an old version of my application. Silly.

willem
I'm sure we have all done something similar :D Best lessons are learned the hardest and all that. :)
Rob Cooper
A: 

I've had a similar problem, where the solution was that I was holding the wrong web.config, one that was generated by visual studio when adding a file or so.