app.config文件如下:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
      <add key="ConnectionString" value="server=127.0.0.1;uid=sa;pwd=xx;database=test"/>
    </configSections>
</configuration>
然后在winform中读取连接字符串string SqlConnectionStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();运行报错说 配置系统未能初始化
请问这是什么错误

解决方案 »

  1.   


    这才是正确的。
    <configuration>
      <appSettings>
        <add key="ConnectionString" value="server=127.0.0.1;uid=sa;pwd=xx;database=test"/>
      </appSettings>
    </configuration>
      

  2.   

    string SqlConnectionStr=ConfigurationManager.AppSettings["ConnectionString"];
    注意这个是与你的exe文件在同一个目录下的app.config文件,而不是你项目源代码所在的app.config文件。
      

  3.   


    exe目录下有一个note.exe.config,我把源代码那里的app.config又拷了一个到exe目录下,还是一样的错误!
      

  4.   


    你把App.config照着这个改一下。
      

  5.   

    楼主你看下你的..\bin\Debug\文件里有app.config文件没?
      

  6.   


    note.exe.config会在你编译工程的时候自动copy到输出目录的,你不需要手动copy
    是你的配置文件写错了,不是configSections,而是appSettings
      

  7.   

     string xmlfile = System.Windows.Forms.Application.ExecutablePath + ".config";
                DataSet ds = new DataSet();
                ds.ReadXml(xmlfile);
                ds.Tables["add"].PrimaryKey = new DataColumn[] { ds.Tables["add"].Columns["name"] };  
                    string strconn= ds.Tables["add"].Rows.Find("DbHelper")["connectionString"].Tostring();