title: Building a relative path connection string to access a SQLite database in c#
body: <p>I’m currently working in c# with a SQLite database file (data.db3) which is located in the application directory. During development, an absolute path has been used and it worked fine so far.  Now I’m trying to access the database by using a relative path, but that fails because of a possibly wrong connection string. The following connection string works fine and was automatically created by the ADO.Net framework.</p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="dataEntities" 
   connectionString="metadata=res://*/DataEntities.csdl|res://*/DataEntities.ssdl|res://*/DataEntities.msl;provider=System.Data.SQLite;provider connection string='data source=&amp;quot;C:\Projekte\DataProvider\data.db3&amp;quot;;datetimeformat=Ticks'" 
   providerName="System.Data.EntityClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Now I tried the following to access the database using a relative path (all fails):</p>
  
  <ol>
  <li><code>dataContext = new dataEntities("Data Source=data.db3");</code></li>
  <li><code>dataContext = new dataEntities("Data Source=.\\data.db3");</code></li>
  <li><code>dataContext = new dataEntities("Data Source=data.db3;Version=3;DateTimeFormat=Ticks;");</code></li>
  <li><code>dataContext = new dataEntities("metadata=res://*/DataEntities.csdl|res://*/DataEntities.ssdl|res://*/DataEntities.msl;provider=System.Data.SQLite;provider connection string='data source=&amp;quot;data.db3&amp;quot;;datetimeformat=Ticks'" providerName="System.Data.EntityClient");</code></li>
  </ol>
  
  <p>Created by the ADO.Net framework:</p>
  
  <pre><code>public partial class dataEntities : ObjectContext
  {
  
      public dataEntities() : base("name=dataEntities", "dataEntities")
      {
          this.ContextOptions.LazyLoadingEnabled = true;
          OnContextCreated();
      }
  
      public dataEntities(string connectionString) : base(connectionString, "dataEntities")
      {
          this.ContextOptions.LazyLoadingEnabled = true;
          OnContextCreated();
      }
  
   /// ……
  </code></pre>
  
  <p>}</p>