I know this is a little too late but I had the same issue as you questioned here and this is what worked for me:
string con = String.Format(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;",
String.Format(
@"{0}\{1}",
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"abcd.accdb"
)
);
The @
enables you to use characters like \
without backslashing these. I always use @
when entering filepaths. Although I can imagine that hard-coding filepaths in your code is probably not the best way to do it, try this instead (What is app.config for?).
The line Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
resolves to the value of the environment variable %APPDATA%
.
Also note that this solution is for accdb
files and if you want to use this for mdb
you need to change the Provider
to Microsoft.JET.OLEDB.4.0
.
I hope this answer helps someone.