日期:2014-05-19  浏览次数:21024 次

如果读取app.config的内容

读取代码如下
    System.Configuration.Configuration   config   =
                                        ConfigurationManager.OpenExeConfiguration(
                                        ConfigurationUserLevel.None);
ConfigurationSection   cs   =   config.GetSection( "applicationSettings ");

结果cs   返回null,
但是用config.GetSection( "connectionStrings ");却可以


app.config的内容如下
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<configuration>
        <configSections>
                <sectionGroup   name= "applicationSettings "   type= "System.Configuration.ApplicationSettingsGroup,   System,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089 "   >
                        <section   name= "Test_ado.Properties.Settings "   type= "System.Configuration.ClientSettingsSection,   System,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089 "   requirePermission= "false "   />
                </sectionGroup>
        </configSections>
        <connectionStrings>
                <add   name= "northwindbysql "   connectionString= "Data   Source=lisong;Initial   Catalog=Northwind;User   ID=sa "
                        providerName= "System.Data.SqlClient "   />
                <add   name= "northwindbywindow "   connectionString= "Data   Source=localhost;Initial   Catalog=Northwind;Integrated   Security=True "
                        providerName= "System.Data.SqlClient "   />
                <add   name= "Test_ado.Properties.Settings.mydbstring "   connectionString= "Data   Source=lisong;Initial   Catalog=Northwind;User   ID=sa "
                        providerName= "System.Data.SqlClient "   />
        </connectionStrings>
        <applicationSettings>
                <Test_ado.Properties.Settings>
                        <setting   name= "myDB "   serializeAs= "String ">
                                <value> northwind </value>
                        </setting>
                </Test_ado.Properties.Settings>
        </applicationSettings>