<connectionStrings>
<add name="connstr"
connectionString="data source=127.101.65.19; database =phone; User ID=mm; Password=mm"
providerName="System.Data.SqlClient" />
</connectionStrings>
在程序中读取,1,引用命名空间:using System.Configuration;2,获取方法public string connectionstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
而AppSetting 字面翻译就是 应用设置.可以将一些常用配置设置在AppSetting, 而很多人都喜欢把数据库的链接放到AppSetting 上面.仅此而已,没有什么太大关联.
写到AppSetting里边
<appSettings >
<add key="Con" value="Data Source=127.101.65.19;Initial Catalog=phone;Persist Security Info=True;User ID=xx;Pwd=yy;Pooling=true;"/>
<add key="InternalProductionCon" value="Data Source=xx;Initial Catalog=InternalProduction;Persist Security Info=True;User ID=yy
;Pwd=xx;Pooling=true;"/>
</appSettings>读取
System.Configuration.ConfigurationSettings.AppSettings["Con"].ToString();