Using a relative path in connection string for Acc

2019-01-15 20:01发布

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"

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

1条回答
手持菜刀,她持情操
2楼-- · 2019-01-15 20:26

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/"));
查看更多
登录 后发表回答