I have a problem with the app.config file. When the configuration file is next to the exe file, then it works perfectly.
But when I place the external config file to another network drive, then it throws a "configuration system failed to initialize" error.
How should I link to the external config file from the app config to get it to work?
Here is the code:
Program.cs
static void Main(string[] args)
{
var conn = ConfigurationManager.ConnectionStrings["conn"];
Console.WriteLine("ConnStr01={0}", conn);
Console.Read();
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings configSource="U:\config\conStr.config">
</connectionStrings>
</configuration>
conStr.config
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="conn"
connectionString="Data Source={server};Initial Catalog={database};Persist Security Info=True;User ID={username};Password={password}"
providerName="System.Data.SqlClient"/>
</connectionStrings>