会员
周边
新闻
博问
闪存
赞助商
YouClaw
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
chiname
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
::
公告
小技巧:用物理路径读取access数据库
小技巧:用物理路径读取access数据库
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;
}
}
}
参见Globals.cs
<
appSettings
>
<
add
key
="ConnectString"
value
="Data Source={0};Password=;Provider=Microsoft.Jet.OLEDB.4.0"
/>
<!--
数据驱动
-->
<
add
key
="DbPath"
value
="DataBaseHover.mdb"
/>
<!--
物理路径
-->
</
appSettings
>
参见web.config
在调用ConnectString时始终是物理路径
D:\Hover\Hover.Web\DataBase\Hover.mdb
HttpRequest.PhysicalApplicationPath 属性
获取当前正在执行的服务器应用程序的根目录的物理文件系统路径。
posted on
2005-03-04 20:24
把我的欢乐带给你
阅读(
352
) 评论(
0
)
收藏
举报
刷新页面
返回顶部