I am trying to use ConfigurationManager
to get the connection string from a project call FileShareAccessLibrary.
This is the code I am writting in order to do this:
ConfigurationManager.ConnectionStrings["FileShareAccessLibrary"].ConnectionString
This is the content of app.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="FileShareAccessLibrary" connectionString="......"
providerName="System.Data.SqlClient" />
<add name="FileShareAccessLibrary.Properties.Settings"
connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
When I run my app I get a NullReferenceException
because ConfigurationManager.ConnectionStrings["FileShareAccessLibrary"]
returns null.
While debugging I noticed that none of the two connection strings are stored inside ConfigurationManager.ConnectionStrings
so I figured that the ConfigurationManager
is pointing to another file.
In my project I have not other app.config
file.
Is there something I am doing wrong here?
Why is ConfigurationManager
not getting my connection string?