Web.config文件中设置数据库连接字段时如下:
<appSettings>
<add key="AccessConnString" value="provider=microsoft.jet.oledb.4.0;datasource="/>
<add key="DbPath" value="~/App_Data/Test .mdb"/>
</appSettings>
在c#代码中创建OleDbConnection 连接,通过MapPath取得服务器上的物理路径:
private static OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["AccessConnString"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["DbPath"]) + ";");