title: SqlCeConnection error deployment
body: <p>When I try to run my application on an other systems (in my case, windows XP virtualized using VM Virtual Box), I got an error trying to connect to the database (I've copied my release folder on my XP version, this folder contains my sdf database file).
  My database is a SQL Server Compact database (sdf file).</p>
  <p>Here is my code to connect to my database:</p>
  <pre><code> if (_Connection == null)
                      _Connection = new SqlCeConnection(@&quot;Data Source = .\Database.sdf&quot;);
  </code></pre>
  <p>It works well when I try on my developpment environment (Windows 8, VS 2012).</p>
  <p>The application starts well on my XP machine but it crashes when the connection to the database has to be done.</p>
  <p>I tried this approach:
  <a href="https://stackoverflow.com/questions/1833640/connection-string-with-relative-path-to-the-database-file">Connection string with relative path to the database file</a></p>
  <p>Code :</p>
  <pre><code>string ConnectionString = @&quot;Data Source=|DataDirectory|\Database.sdf&quot;;
  string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
  string path = (System.IO.Path.GetDirectoryName(executable));
  AppDomain.CurrentDomain.SetData(&quot;DataDirectory&quot;, path);
  
  _Connection = new SqlCeConnection(ConnectionString);
  </code></pre>
  <p>But when I try to compile in release mode, I have some errors:</p>
  <blockquote>
  <p>Error 1   The database file is not found. Check the path to the
  database. [ Data Source =
  C:\Users\Benj\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\1r55aqij.l5f\p2ffjoyu.4ex\Database.sdf
  ] C:\Users\Benj\Travail\Projets\UNISO\Programme\UNISO
  V1.0\UNISO\UNISO\Pages\FAQEdit.xaml   14  9   UNISO</p>
  </blockquote>
  <p>The database must be deployed in the application folder.</p>
  <p>I've tried this to deploy my application without installing sql server compact:
  <a href="http://msdn.microsoft.com/en-us/library/vstudio/aa983326.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/vstudio/aa983326.aspx</a></p>
  <p>But I don't want to use the Publish Wizard. I just wan to share and run my program by my release folder.</p>
  <p><strong>EDIT :</strong></p>
  <p>When I install <a href="http://www.microsoft.com/fr-fr/download/details.aspx?id=17876" rel="nofollow noreferrer">SQL Server Compact</a> on my XP VM, it works well. So the problem is not about the sdf file path.
  The problem may come from the way to add the SQL Server Compact DLLs to my project. But I've done exactly what it's said in the link above (except the deployment with the wizard).</p>
  <p><strong>UPDATE :</strong></p>
  <p>As you can see on this link, <a href="http://msdn.microsoft.com/en-us/library/vstudio/aa983326.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/vstudio/aa983326.aspx</a>, there are two way to deploy a SQL server Compact application.
  The first way is to use the traditional Windows installer. I tried it and it works well, my application works perfectly, but I don't want to use this way (I don't want to install things on the client computer, I just want to share a standalone folder).
  The second way is the Private File–Based Deployment methode (which is the methode that I want to use).
  I followed all the described instructions in the &quot;Private File-Based Deployment&quot; part in the link above, but when I run the application, it stops when connecting to the database.
  Is there something I'm missing?</p>