Home >Database >Mysql Tutorial >ACCESS在Web.config里设置连接字符串

ACCESS在Web.config里设置连接字符串

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:12:291129browse

在web.config中使用象asp那样的Server.MapPath取数据库路径 但web.config不认识Server.MapPath,此方法致使程序无法调试,行不通。 如下方法,可以方便的移植程序路径而不必再去修改access数据库路径。 在web.config中的写法如下: appSettings add key="Con

在web.config中使用象asp那样的Server.MapPath取数据库路径
但web.config不认识Server.MapPath,此方法致使程序无法调试,行不通。

如下方法,可以方便的移植程序路径而不必再去修改access数据库路径。

在web.config中的写法如下:




程序中的数据访问类中我把"ConnStr"和"dbPath"取出来再连接成一个字符串
代码如下:

   ///


  /// (静态)返回数据库连接串。
  ///

  protected static string GetConnString()
  {
   return
System.Configuration.ConfigurationSettings.AppSettings["ConnStr"]+   System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["DataPath"])+";";
  }

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