Reputation: 825
I added System.Configuration.dll
as a reference. When I try to get a connection string by name, I get a null reference exception. So I tried to see if it has any using the following code:
for (int i = 0; i < ConfigurationManager.ConnectionStrings.Count; i++)
{
string ad = ConfigurationManager.ConnectionStrings[0].ConnectionString;
}
I found out it has 3 connection strings! I am not sure from where, because I have only one in my config file, and none of these three are the one I added.
Next, I checked my appDomain:
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
I've read that file inside my application; it is exactly the same as my AppConfig file, and contains my connection string.
Why doesn't configuration manager find it, and what can I do to fix it?
Upvotes: 3
Views: 4019
Reputation: 1953
Make sure you are using the correct config file for your build.
Ie: If you are debubbing, Visual Studio can have an app/web.config for your debug and another for release. So make sure you are looking at the correct one.
Upvotes: 1