解决方案一
在 Web
请看代码
<appSettings>
<add key="DBDriver" value="Provider=MicrosoftJet OLEDB ; Data Source ="/>
<add key="DBName" value="Companymdb"/>
</appSettings>
在数据库访问层
/**//// <summary>
/// 从WebConfig取得数据库联接字符串
/// </summary>
//从配置文件中得到数据库名称
public static readonly string DBName = ConfigurationManagerAppSettings Get("DBName") ToString();
//从配置文件中得到数据库驱动
public static readonly string DBDriver = ConfigurationManagerAppSettings Get("DBDriver") ToString();
//得到数据库连接字符串
private static string DBConnectionString = DBDriver + HttpContextCurrent Server MapPath(HttpContext Current Request ApplicationPath + "/App_Data/") + DBName;
//建立数据库连接对象
private static OleDbConnection OleDbConn = new OleDbConnection(DBConnectionString);
这样设置后
解决方案二
<appSettings>
<add key="SQLConnString" value="provider=microsoftjet oledb ;data source="/>
<add key="dbPath" value="~/App_Data/mydatamdb"/>
</appSettings>
程序中的数据访问类中我把"SQLConnString"和"dbPath"取出来连接成一个字符串"CONN_STRING_NON_DTC"
public static readonly string CONN_STRING_NON_DTC = SystemConfiguration ConfigurationManager AppSettings["SQLConnString"] ToString() + System Web HttpContext Current Server MapPath(ConfigurationManager AppSettings["dbPath"]) + ";";