I have a folder 'Data' in my WPF application in which there is an .sdf database file. This file is the database for my application.
When developing my app I used a fixed path to my db like this:
'Data Source=P:\Dropbox\Projects\MembersApp\MembersApp\bin\Debug\Data\RF_db.sdf'
Now I want to use the |DataDirectory| value so that the app always can find the db, were ever the app is installed. I found this solution on StackOverflow:
string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
string path = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", path);
string dataSourceHome = "Data Source=|DataDirectory|\RF_db.sdf";
But is giving me an error on the last line 'Bad compile constant value'. I've tried with:
string dataSourceHome = @"Data Source=|DataDirectory|\RF_db.sdf";
But that doesn't work.
Any idea what's wrong here?