Home >Database >Mysql Tutorial >asp.net连接access数据库路径问题

asp.net连接access数据库路径问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:21:50896browse

解决方案一: 在 Web.Config 中配置 Access数据库教程驱动和数据库文件名称。 请看代码 appSettings add key=DBDriver value=Provider=Microsoft.Jet.OLEDB.4.0; Data Source =/ add key=DBName value=Company.mdb/ /appSettings 在数据库访问层,如 OleDBHe

 解决方案一: 

在 Web.Config 中配置 Access 数据库教程驱动和数据库文件名称。 
请看代码

 
 
 
 

在数据库访问层,如 OleDBHelper.cs 中获得 Access 数据库链接字符串。

/**////  
/// 从Web.Config取得数据库联接字符串 
///
 
//从配置文件中得到数据库名称 
public static readonly string DBName = ConfigurationManager.AppSettings.Get("DBName").ToString(); 
//从配置文件中得到数据库驱动 
public static readonly string DBDriver = ConfigurationManager.AppSettings.Get("DBDriver").ToString(); 
//得到数据库连接字符串 
private static string DBConnectionString = DBDriver + HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/App_Data/") + DBName; 
//建立数据库连接对象 
private static OleDbConnection OleDbConn = new OleDbConnection(DBConnectionString); 

这样设置后,,无论在任何子目录,都能通过以上代码正确的访问数据库。


解决方案二:





程序中的数据访问类中我把"SQLConnString"和"dbPath"取出来连接成一个字符串"CONN_STRING_NON_DTC"

public static readonly string CONN_STRING_NON_DTC = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"]) + ";";
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn