private static string Constring;
/// <summary>
/// 数据连接字符串
/// </summary>
public static string ConnectString
{
get
{
if(Constring==null)
{
Constring=string.Format(System.Configuration.ConfigurationSettings.AppSettings["ConnectString"],
System.Web.HttpContext.Current.Request.PhysicalApplicationPath+(System.Configuration.ConfigurationSettings.AppSettings["DbPath"]));
return Constring;
}
else
{
return Constring;
}
}
}
/// <summary>
/// 数据连接字符串
/// </summary>
public static string ConnectString
{
get
{
if(Constring==null)
{
Constring=string.Format(System.Configuration.ConfigurationSettings.AppSettings["ConnectString"],
System.Web.HttpContext.Current.Request.PhysicalApplicationPath+(System.Configuration.ConfigurationSettings.AppSettings["DbPath"]));
return Constring;
}
else
{
return Constring;
}
}
}
<appSettings>
<add key="ConnectString" value="Data Source={0};Password=;Provider=Microsoft.Jet.OLEDB.4.0" /> <!--数据驱动-->
<add key="DbPath" value="DataBaseHover.mdb" /><!--物理路径-->
</appSettings>
<add key="ConnectString" value="Data Source={0};Password=;Provider=Microsoft.Jet.OLEDB.4.0" /> <!--数据驱动-->
<add key="DbPath" value="DataBaseHover.mdb" /><!--物理路径-->
</appSettings>
在调用ConnectString时始终是物理路径
D:\Hover\Hover.Web\DataBase\Hover.mdb