我建了个Winform工程,后来才添加了一个App.config配置文件,把数据库的连接串放在该配置文件中(因为要同时连三个不同的数据库,1×Sybase+2×Oracle)。但是我直接用System.Configuration.ConfigurationSettings.AppSettings[参数名]无法取得参数值(参数都放在AppSettings里)小弟刚接触C#和.NET,什么都不懂,望指教,急

解决方案 »

  1.   

    另:App.config的内容如下:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="ConnStr_1" value="Data Source='ase_test';Port=5500;UID='sa';PWD='';Database='test';"/>
    <add key="ConnStr_2" value="user id=test;data source=GZ1;password=test"/>
    <add key="ConnStr_3" value="user id=test;data source=GZ2;password=test"/>
    </appSettings>
    </configuration>
      

  2.   

    把 App.config 改为 App.exe.config,放在 App.exe 同一个目录中。
      

  3.   

    用.exe启动你程序才可以
    如果用VS.net启动你的程序他是读另一个文件的
      

  4.   

    读取web.config 或者 app.config中自定义配置的值的属性,常用2种方法.假设有如下配置:<appSettings> 
    <add key="A" value="config with A"/> 
    <add key="B" value="config with B"/> 
    </appSettings> using System.Configuration;[A] 方法string strTest  = ConfigurationSettings.AppSettings["A"];  // get A 's value[B] 方法AppSettingsReader appReader = new AppSettingsReader();
    string strTest = appReader.GetValue(strKey,typeof(string)).ToString();e.g.private string GetConfig(string strKey)
    {
    AppSettingsReader appReader = new AppSettingsReader();
    string strReturn;
    try
    {
    strReturn = appReader.GetValue(strKey,typeof(string)).ToString();
    }
    catch(Exception ex)
    {
    strReturn = ex.Message.ToString();
    }
    finally
    {
    appReader = null;
        
    }
    return strReturn;
    }