如何读取 app.config 里面 的 配置信息 ?.net framework 2.0

app.config 信息如下

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup,
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Model.set" type="System.Configuration.ClientSettingsSection, 
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>

<userSettings>
<Model.set>
<setting name="Connection" serializeAs="String">
<value>Data Source=192.168.0.254;Initial Catalog=DB;User ID=fhz;Password=fhzadmin;</value>
</setting>
<setting name="Path" serializeAs="String">
<value>D:\code\</value>
</setting>
</Model.set>
</userSettings>
</configuration>

怎么读取呢????

ConfigurationManager.AppSettings["Connection"].ToString();

读不到呃  

喵喔喔
浏览 410回答 5
5回答

慕后森

<appSettings>     <add key="Connection" value="Data Source=192.168.0.254;Initial Catalog=DB;User ID=fhz;Password=fhzadmin;" />   </appSettings>我记得是这样写的。。。要不我也不知道怎么读取

慕容708150

应该能读到的一般情况下ConfigurationManager.AppSettingd[""].Tostring();或者ConfigurationManager.ConnecString.Tostring();来读取的

呼如林

app.config 应该这样写吧 <appSettings>     <add key="Connection" value="Data Source=192.168.0.254;Initial Catalog=DB;User ID=fhz;Password=fhzadmin;" />   </appSettings>

qq_遁去的一_1

string connection=ConfigurationManager.AppSetting["Connection"].ToString();
打开App,查看更多内容
随时随地看视频慕课网APP