title: Database connection from WPF
body: <p>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.</p>
  
  <p>When developing my app I used a fixed path to my db like this: </p>
  
  <pre><code>'Data Source=P:\Dropbox\Projects\MembersApp\MembersApp\bin\Debug\Data\RF_db.sdf'
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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";
  </code></pre>
  
  <p>But is giving me an error on the last line 'Bad compile constant value'. I've tried with:</p>
  
  <pre><code>string dataSourceHome = @"Data Source=|DataDirectory|\RF_db.sdf";
  </code></pre>
  
  <p>But that doesn't work. </p>
  
  <p>Any idea what's wrong here?</p>