title: SQLite EF6 programmatically set connection string at runtime
body: <p>I try to migrate form EF 3.5 to 6 (with SQLite as database). We can not set the connection string in the app config file (this works without problems with ef6). We have to set connection string programmatically at runtime (after user has selected the SQLite file).</p>
  
  <p>Here is our app.config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="testContext" connectionString="data source=Data\testdb.sqlite;Foreign Keys=True"
        providerName="System.Data.SQLite" /&gt;
    &lt;/connectionStrings&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="System.Data.SQLite" /&gt;
        &lt;remove invariant="System.Data.SQLite.EF6" /&gt;
        &lt;add name="System.Data.SQLite" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here ist the DbContext</p>
  
  <pre><code>public class FirmwareContext : DbContext
  {
      public FirmwareContext()
          : this(DEFAULT_CONNECTION)
      {
  
      }
  
      public FirmwareContext(string connextionNameOrString)
          : base(connextionNameOrString)
      {
  
      }
  }
  </code></pre>
  
  <p>If I connect with the connecation name from app.config all works without problems. If I try to pass the connection string with the second constructor this fails</p>
  
  <p>Here is small example</p>
  
  <pre><code>SQLiteConnectionStringBuilder builder =
      factory.CreateConnectionStringBuilder() as SQLiteConnectionStringBuilder;
  builder.DataSource = dataSource; // Path to file name of the user
  builder.ForeignKeys = true;
  
  var context = new FirmwareContext(builder.ToString());
  
  var context = new FirmwareContext(builder.ToString());
  var test = context.Firmware.FirstOrDefault();
  </code></pre>
  
  <p>I got the following exception ("Schlüsselwort wird nicht unterstützt: 'foreign keys'.") => The key 'foreign key' is nott supported. If I remove the foreign key set, I got the following exception ("The provider did not return a ProviderManifestToken string.") and some inner exceptions.</p>
  
  <p>It seems that the bas(connectionString) build the MSSQL connection string and for SQLite.</p>
  
  <p>How can I make my second constructor campatible with sqlite?</p>