title: EFCore SQLite connection string with relative path in asp.net
body: <p>I have just added SQLite to my asp.net webApi project, and am having trouble working out how get the path to the App_Data folder to pass to <code>DbContextOptionsBuilderUseSqlite</code></p>
  
  <p>I have the following in the <code>web.config</code> I have a link to an external a config file with the conenction string...</p>
  
  <pre><code>&lt;connectionStrings configSource="config\connectionStrings.config"/&gt;
  </code></pre>
  
  <p>and in there I have...</p>
  
  <pre><code>    &lt;connectionStrings&gt;
        &lt;add name="MyDatastore"
               connectionString="DataSource=./App_Data/test.sqlite" /&gt;
      &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>And in my <code>DbContext.OnConfiguring</code> I Have....</p>
  
  <pre><code>    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
            if (!optionsBuilder.IsConfigured)
            {
              string path = WebConfigurationManager.ConnectionStrings["MyDatastore"].ConnectionString;
              optionsBuilder.UseSqlite(path);
            }
      }
  </code></pre>
  
  <p>The path is correctly retrieved (I can see I get the path as configured on <code>connectionStrings.config</code></p>
  
  <p>so <code>./App_Data/test.sqlite</code> is passed to <code>optionsBuilder.UseSqlite(path)</code>.</p>
  
  <p>However, I get the following error...</p>
  
  <pre><code>SQLite Error 14: 'unable to open database file'. 
  </code></pre>
  
  <p>If I use just <code>connectionString="DataSource=test.sqlite" /&gt;</code> then it seems to magically find the file in the App_Data folder, when I ran on my dev machine in debug, but I had problems on another machine (release build). I assume it is the path, though all I get back is 'unable to open database file'.</p>
  
  <p>I also tried..</p>
  
  <pre><code> connectionString="DataSource=|DataDirectory|test.sqlite" /&gt;
  </code></pre>
  
  <p>This gives me a <code>Illegal characters in path</code> error.</p>
  
  <p>The following does work (full path)</p>
  
  <pre><code> connectionString="d:\0\test.sqlite" /&gt;
  </code></pre>
  
  <p>But I want to be able to use relative paths, eg maybe even <code>.\datastore\test.sqlite</code>.</p>
  
  <p>Does any one have any ideas on this?</p>
  
  <p>Thanks in advance</p>