对于类库里读取解决方案web.config文件里字符串的方法
一.读取键值对的方法;
1.添加引用
using System.Configuration;
2.web.Config配置节
<appSettings>
<!--现场维护从当前月向前跨几个月-->
<add key="CrossMonthNum" value="2"/>
</appSettings>
3.代码
public static string FileUploadPath
{
get
{
//return System.Web.Configuration.WebConfigurationManager.AppSettings["fileStorePath"];
return ConfigurationManager.AppSettings["fileStorePath"];
}
}
二.读取数据库连接串
1.添加引用
using System.Configuration;
2.web.Config配置节
<connectionStrings>
<!--Oracel链接-->
<add connectionString="metadata=res://*/ERP.csdl|res://*/ERP.ssdl|res://*/ERP.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=FT8000;PASSWORD=fterp201501!!;PERSIST SECURITY INFO=True;USER ID=ft800"" providerName="System.Data.EntityClient"/>
<add connectionString="Data Source=192.168.10.611;Initial Catalog=FTCE_ACCS;Persist Security Info=True;User ID=sa;Password=P@ssw0rd" providerName="System.Data.SqlClient"/>
<add connectionString="Data Source=ftcesys;Persist Security Info=True;User ID=lqmuser;Password=qmuser" providerName="System.Data.OracleClient"/>
<!--erp数据库接口-->
<add connectionString="Data Source=fterp;Persist Security Info=True;User ID=ft800;Password=fterp201501!!" providerName="System.Data.OracleClient"/>
<add connectionString="Data Source=fterp;Persist Security Info=True;User ID=ft800;Password=fterp201501!!" providerName="System.Data.OracleClient"/>
<!--临时使用 模拟特采系统或其他SQLServer数据库接口-->
<add connectionString="Data Source=192.168.130.111;Initial Catalog=FTCE_Interface;Persist Security Info=True;User ID=sa;Password=P@ssw0rd" providerName="System.Data.SqlClient"/>
</connectionStrings>
3.读取字符串代码
ConfigurationManager.ConnectionStrings["FTCE_CW_SystemCon"].ConnectionString