Using relative path in connection string for Access DB in C #

I am trying to get this line in my web.config file to use a relative path instead of hard-coded, but nothing works. I can find material for SQL and mySQL DB

<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 to do it

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

but then it searches for something in this folder where it does not exist.

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

Is there any way to get this relatively? It is located in the AppData folder of the project file.

+4
source share
1 answer

I looked around and earned. I inserted this line in the Application_Start method of the Global.asax file

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

Source: https://habr.com/ru/post/1443348/


All Articles