Question

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).

Was it helpful?

Solution

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.

OTHER TIPS

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.

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?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top