ACCESS数据库的话,写法为:
引用为:
public partial class _Default : System.Web.UI.Page
{
private static string connString = String.Format(ConfigurationSettings.AppSettings["AccessConnStr"], HttpContext.Current.Server.MapPath("../"));//如果是同目录,用MapPath(".")下级子目录用../
protected void Page_Load(object sender, EventArgs e)
{
}
}
另:在CONFIG文件中,是不支持Server.MapPath的,因为那就是一个XML文件,本身是不能运算的。
之后在程序里可以用System.Configuration.ConfigurationManager.AppSettings["P"]取值
在Web.config中有两种方式:
一,写到
二,
在程序里引用都是一样的:
string connStr = System.Configuration.ConfigurationManager.AppSettings["conn"];