title: SQL Server Compact 4.0 database not detected after ClickOnce deploy
body: <p>I have a WPF C# application and an SQL Server Compact 4.0 database. Initially I had my Data Source pointing to the location of the database like this:</p>
  
  <pre><code>public static SqlCeConnection sqlCeConnection = new SqlCeConnection(@"C:\VSP Road Maintenance Solution\VSPApp_Mono\VSPApp\VSPCompactDatabasse.sdf");
  </code></pre>
  
  <p>This worked great on my local machine but when I wanted to package the application (ClickOnce), it didn't work on the client's machine. After going through MSDN documentation on creating an ms sql server compact database and deploying it and other related similar issues such as <a href="http://social.msdn.microsoft.com/Forums/sqlserver/en-US/dc31ea59-5718-49b6-9f1f-7039da425296/where-is-datadirectory-?forum=sqlce" rel="nofollow">http://social.msdn.microsoft.com/Forums/sqlserver/en-US/dc31ea59-5718-49b6-9f1f-7039da425296/where-is-datadirectory-?forum=sqlce</a> and <a href="http://msdn.microsoft.com/en-us/library/37z40s1c(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/37z40s1c(v=vs.110).aspx</a></p>
  
  <p>I tried to access the <code>AppDomain</code> via C# like (in <code>App.xaml.cs</code>):</p>
  
  <pre><code>protected override void OnStartup(StartupEventArgs e)
  {
      base.OnStartup(e);
  
      Process p = Process.GetCurrentProcess(); // Pick desired process
      p.PriorityClass = ProcessPriorityClass.RealTime; // Assign priority
  
      AppDomain currentDomain = AppDomain.CurrentDomain;
      currentDomain.SetData("DataDirectory", @"C:\VSP Road Maintenance Solution\VSPApp_Mono\VSPApp");
  }
  </code></pre>
  
  <p>And now to create a connection to the database I just: </p>
  
  <pre><code>public static string dbFileName = "VspCompactDatabase.sdf";
  SqlCeConnection sqlCeConnection = new SqlCeConnection(@"Data Source=|DataDirectory|\" +dbFileName);
  </code></pre>
  
  <p>This works on my local machine too, but when I create the ClickOnce package. The application does not seem to find the database. All the prerequisite software gets installed. Why is it that when the application is deployed on a different machine, the seems to be no connection with the database?  </p>