惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
AWS News Blog
AWS News Blog
美团技术团队
G
Google Developers Blog
宝玉的分享
宝玉的分享
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
小众软件
小众软件
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
IT之家
IT之家
PCI Perspectives
PCI Perspectives
人人都是产品经理
人人都是产品经理
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
SecWiki News
SecWiki News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
T
Threatpost
P
Proofpoint News Feed
Y
Y Combinator Blog
Cloudbric
Cloudbric
T
Tor Project blog
量子位
博客园_首页
B
Blog
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - 雷明

Ado.Net读取Excel常见问题总结 Win7 安装.net framework 4.0 失败,错误HRESULT 0xc8000222解决办法 Excel中删除链接 ipad 3.2.2 IPAD 越狱教程 代理上网后localhost使用不了,只能使用127.0.0.1解决 Windows API函数大全 一个技术转销售人员的感悟--深刻(转) 两个Excel表联动 orcale数据库的导入导出 ORACLE 创建表空间 销售七字真诀 十年创业的一封信 业务员成长计划(转载业务员网) Nokia5230刷机呕心历程 .net 消息队列简单实例 开启SHAREPOINT 2007匿名用户搜索功能及moss搜索界面样式更换 MOSS爬网-搜索自定义带参数信息 WCF创建Rest服务(附:.net2.0创建Rest服务) Hosting WCF in SharePoint 2007 (Part 1) 基本部署(转)
ASP.NET 链接 Access 数据库路径问题最终解决方案
雷明 · 2011-07-29 · via 博客园 - 雷明

当做小项目用 ASP.NET + Access 数据库时,总是遇到数据库路径问题,本人以前的解决方法是每次访问数据库时,把链接字符串以参数的形式传到数据访问层,实施起来相当麻烦,这次找到了一个比较好的方案,这是本人目前的最终解决方案(如题) ^_^
解决方案一:
在 Web.Config 中配置 Access 数据库驱动和数据库文件名称。
请看代码
<appSettings>
<add key="DBDriver" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source ="/>
<add key="DBName" value="Company.mdb"/>
</appSettings>
在数据库访问层,如 OleDBHelper.cs 中获得 Access 数据库链接字符串。
/**//// <summary>
/// 从Web.Config取得数据库联接字符串
/// </summary>
//从配置文件中得到数据库名称
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);
这样设置后,无论在任何子目录,都能通过以上代码正确的访问数据库。

解决方案二:

<appSettings>
<add key="SQLConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>
<add key="dbPath" value="~/App_Data/mydata.mdb"/>
</appSettings>
程序中的数据访问类中我把"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"]) + ";";