1

Used console application and I have a problem on the app.config file. By right, the code should be correct according to the various sources found in the Internet but my coding is not working for no reason. Anyone can advise me on this?

And the <configuration> appears to be underlined with wriggly blue line, is it a warning or something? I dont know why it appears like this.

[EDITED]

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSetting></configSetting>
    <connectionStrings>
        <add name="Production"
             providerName="System.Data.SqlClient"
             connectionString="Data Source=EBSDLAB1SERVER2;Initial Catalog=Production;Integrated Security=True"/>
    </connectionStrings>
</configuration>

The error shows, Unhandled Exception: System.Configuration.ConfigurationErrorException:Configuration system fail to initialize ---
System.Configuration.ConfigurationErrorException: Unrecognized configuration section connectionstring
Configuration system failed to initialize

KyleMit
  • 30,350
  • 66
  • 462
  • 664
CHOCOx33
  • 25
  • 1
  • 1
  • 7

2 Answers2

2

In your App.Config file you need a section for connection strings, it should look like:

<connectionStrings>
  <clear />
  <add name="Production" 
       providerName="System.Data.ProviderName" 
       connectionString="ConnectionStringGoesHere" />
</connectionStrings>

There's more information regarding this here.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Darren
  • 68,902
  • 24
  • 138
  • 144
  • I did add too, just what I have mentioned above. But it still have the error. the app.config file is as following: – CHOCOx33 Jun 25 '13 at 09:08
  • 1
    I think your "connectionstring" needs to be "connectionString"...from MSDN: "The Web.config file is case-sensitive, so specifying a value for 'FileEncoding' will not have the desired effect, but specifying a value for 'fileEncoding' will". – Seth Moore Jun 26 '13 at 12:37
1

I managed to solve this problem which is to copy the app.config file to the same folder as the console application.exe and rename the app.config file according to the console application.exe!

Thank you all for the help!

CHOCOx33
  • 25
  • 1
  • 1
  • 7