In my windows forms program I have an App.Config file:
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:
Now I get:
Configuration system failed to initialize
I tried to add in an element for AppSettings:
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
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