In my application when I try to get the connection string by using this code :
System.Configuration.ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
It throws an exception that "Configuration System Failed To Initialize". Where is the format of app.config wrong ?
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ConStr" connectionString="Integrated Security=false;Persist Security Info=False;User ID=funny;password=veryfunny;Initial Catalog=vegimanager;Data Source=.\sqlexpress;"/>
</connectionStrings>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Vegi_Manager.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<Vegi_Manager.Properties.Settings>
<setting name="FIRMNAME" serializeAs="String">
<value/>
</setting>
<setting name="FIRMADDRESS" serializeAs="String">
<value/>
</setting>
<setting name="FIRMCITY" serializeAs="String">
<value/>
</setting>
<setting name="FIRMSTATE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMPHONE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMMOBILE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMEMAIL" serializeAs="String">
<value/>
</setting>
<setting name="FIRMTIN" serializeAs="String">
<value/>
</setting>
<setting name="FIRMPAN" serializeAs="String">
<value/>
</setting>
<setting name="FIRMMANDITAXNO" serializeAs="String">
<value/>
</setting>
<setting name="INITIALFONFIGDONE" serializeAs="String">
<value>False</value>
</setting>
<setting name="FIRMJURISDICTION" serializeAs="String">
<value/>
</setting>
<setting name="FIRMBANKDETAILS" serializeAs="String">
<value/>
</setting>
<setting name="FIRMDETAILS" serializeAs="String">
<value/>
</setting>
<setting name="BILLFORMATNO" serializeAs="String">
<value>0</value>
</setting>
<setting name="PRINTERNAME" serializeAs="String">
<value/>
</setting>
</Vegi_Manager.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
System configuration is a term in systems engineering that defines the computer hardware, the processes as well as the various devices that comprise the entire system and its boundaries.
A: When you compile an application, its app. config is copied to the bin directory1 with a name that matches your exe. For example, if your exe was named "test.exe", there should be a "text.exe. config" in your bin directory.
Try putting the configSections
as the first child element of configuration
, because configSections
should be the first element of configurations
So your config file will go like this:
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Vegi_Manager.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ConStr" connectionString="Integrated Security=false;Persist Security Info=False;User ID=funny;password=veryfunny;Initial Catalog=vegimanager;Data Source=.\sqlexpress;"/>
</connectionStrings>
<userSettings>
<Vegi_Manager.Properties.Settings>
<setting name="FIRMNAME" serializeAs="String">
<value/>
</setting>
<setting name="FIRMADDRESS" serializeAs="String">
<value/>
</setting>
<setting name="FIRMCITY" serializeAs="String">
<value/>
</setting>
<setting name="FIRMSTATE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMPHONE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMMOBILE" serializeAs="String">
<value/>
</setting>
<setting name="FIRMEMAIL" serializeAs="String">
<value/>
</setting>
<setting name="FIRMTIN" serializeAs="String">
<value/>
</setting>
<setting name="FIRMPAN" serializeAs="String">
<value/>
</setting>
<setting name="FIRMMANDITAXNO" serializeAs="String">
<value/>
</setting>
<setting name="INITIALFONFIGDONE" serializeAs="String">
<value>False</value>
</setting>
<setting name="FIRMJURISDICTION" serializeAs="String">
<value/>
</setting>
<setting name="FIRMBANKDETAILS" serializeAs="String">
<value/>
</setting>
<setting name="FIRMDETAILS" serializeAs="String">
<value/>
</setting>
<setting name="BILLFORMATNO" serializeAs="String">
<value>0</value>
</setting>
<setting name="PRINTERNAME" serializeAs="String">
<value/>
</setting>
</Vegi_Manager.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
This is a bit late I know but when I remove this:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
then the error disappears.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With