4

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

dbc
  • 104,963
  • 20
  • 228
  • 340
Un Known
  • 179
  • 1
  • 3
  • 15
  • Checkout this link http://www.connectionstrings.com/access-2007 bookmark this link for future references- http://www.connectionstrings.com/ – MethodMan Nov 01 '12 at 00:58
  • thx DJ KRAZE, but I already have the connection string working. I just need to get it to be a relative path or at least change the path of |Data Directory| – Un Known Nov 01 '12 at 03:12
  • possible duplicate of [Relative path reference in WebConfig.ConnectionString](http://stackoverflow.com/questions/125157/relative-path-reference-in-webconfig-connectionstring) – Fionnuala Nov 01 '12 at 11:23
  • but where can I change the path of |DataDirectory| so it doesn't look in "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DevServer\\10.0" but instead look in my App_Data folder? – Un Known Nov 01 '12 at 18:08

1 Answers1

6

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/"));
Un Known
  • 179
  • 1
  • 3
  • 15