4

Possible Duplicate:
Using a relative path in connection string for Access DB in C#

This is my current connection string in web.config

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

but instead of looking in the App_Data folder, the application looks in

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

which isn't right. How and where can I change the default location of |DataDirectory| to be the relative path of App_Data inside the project folder?

Community
  • 1
  • 1
Un Known
  • 179
  • 1
  • 3
  • 15

1 Answers1

7

You need to call the AppDomain.SetData method to specify where the |DataDirectory| points to:

AppDomain.CurrentDomain.SetData("DataDirectory", "YourPath");
platon
  • 5,310
  • 1
  • 22
  • 24
  • 1
    Thanks for the help @platon, I looked into it a little more and used this line to get it working `AppDomain.CurrentDomain.SetData("DataDirectory", Server.MapPath("~/App_Data/"));` – Un Known Nov 01 '12 at 23:01