发布网友 发布时间:2022-04-22 15:04
共2个回答
懂视网 时间:2022-05-01 07:28
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);而在一些web项目中,可以尝试使用以面代码来取出配置文件中的信息
1 Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
从配置文件中取出数据库链接字符串的技巧
标签:
热心网友 时间:2022-05-01 04:36
AppSettings和ConnectionStrings的区别
在 .NET Framework 2.0中,ConfigurationManager类新增了两个属性AppSettings和ConnectionStrings专门用来获取配置文件AppSettings和ConnectionStrings节的数据,使用方法如下:
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = ConfigurationManager.ConnectionStrings["connectionStringsName"].ToString();
Label2.Text = ConfigurationManager.AppSettings["appSettingsName"].ToString();
}
}
<connectionStrings>和<appSettings>这个的区别
1.<connectionStrings>
<connectionStrings>
<add name="SYXTConnectionString" connectionString="Data Source=LEIKE;Initial Catalog=SYXT;User ID=sa;Password=sa"
providerName="System.Data.SqlClient" />
</connectionStrings>
2.<appSettings>:
<add key="connectionstring1" value="data source=192.168.123.201;initial catalog=webmedlink;persist security info=False;user id=sa;password=KSDChagd2004;packet size=4096">
</add>
后者是在Framework2.0以后才有的.