在C#中使用的连接字符串中的相对路径为Access数据库 [英] Using a relative path in connection string for Access DB in C#

查看:622
本文介绍了在C#中使用的连接字符串中的相对路径为Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这条线在我的web.config文件中使用相对路径,而不是硬编码之一,但似乎没有奏效。我只能找到的东西了SQL和MySQL的DB

I'm trying to get this line in my web.config file to use a relative path instead of hardcoded one, but nothing seems to be working. I can only find stuff for SQL and mySQL DBs

<connectionStrings>
<add name="dbConnection" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Mike\Desktop\GeauxEat NEW\GeauxEat\App_Data\GeauxEatAccessDB.accdb"/>
</connectionStrings>



我试图使它

I tried making it

<add name="dbConnection" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|Data Directory|\GeauxEatAccessDB.accdb"/>



但随后它会查找该文件夹的东西在它不存在。

but then it looks for something in this folder where it doesn't exist.

"C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DevServer\\10.0"

有没有办法得到它相对的?它位于项目文件的AppData文件夹

Is there any way to get it relative? It's located in the AppData folder of the project file

推荐答案

我环顾四周,得到它的工作。我插入这一行到Global.asax文件

I looked around and got it working. I inserted this line into the Application_Start method of the Global.asax file

AppDomain.CurrentDomain.SetData("DataDirectory", Server.MapPath("~/App_Data/"));

这篇关于在C#中使用的连接字符串中的相对路径为Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆