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

4
  • Checkout this link connectionstrings.com/access-2007 bookmark this link for future references- connectionstrings.com Commented Nov 1, 2012 at 0: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| Commented Nov 1, 2012 at 3:12
  • possible duplicate of Relative path reference in WebConfig.ConnectionString Commented Nov 1, 2012 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? Commented Nov 1, 2012 at 18:08

1 Answer 1

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/"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.