Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't find ConfigurationManager

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
In my windows forms program I have an App.Config file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="connection"
         connectionString="Server=TFS-PC;Database=MyDB;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

If I do:

myConnectionString = System.Configuration.ConfigurationSettings.AppSettings["Connection"];

It goes through fine but myConnectionString is null.

I tried changing the app config by taking out the connectionString elements:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <add name="connection"
         connectionString="Server=TFS-PC;Database=CSpearAndAssociates;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient" />
</configuration>

Now I get:

Configuration system failed to initialize

I tried to add in an element for AppSettings:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add name="connection"
         connectionString="Server=TFS-PC;Database=CSpearAndAssociates;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient" />
  </appSettings>
</configuration>

Now I get:

Unrecognized attribute 'name'. Note that attribute names are case-sensitive. (C:\Users\tfs\documents\visual studio 2010\Projects\SpearASCWeb\TestData\bin\Debug\TestData.vshost.exe.Config line 4).

'name' was fine with the other elements.

I also tried to use ConfigurationManager as at one point it said ConfigurationSettings was old and should use ConnectionManager.
But I couldn't get it to accept it.

What am I doing wrong here?

Thanks,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top