title: Entity Framework runtime connection string
body: <p>I'd like to supply the connection string for my database at runtime. I am using the Entity Framework. This is what I have so far</p>
  
  <pre><code>class MyClassDBContext:DbContext
  {
    public MyClassDBContext(string str) : base(str)
    {
      this.Database.Connection.ConnectionString = str;
    }
  }
  </code></pre>
  
  <p>To use the above code, I tried</p>
  
  <pre><code>//create connection string
  EntityConnectionStringBuilder myConn = new EntityConnectionStringBuilder();
  myConn.Provider = "System.Data.SqlClient";
  myConn.ProviderConnectionString = "user id=xxxx;password=xxxx;server=localhost;database=xxxx;connection timeout=30";
  
  //inject the connection string at runtime
  MyClassDBContext a = new MyClassDBContext(myConn.ToString())
  </code></pre>
  
  <p>The above code gave me an error saying "Provider keyword not supported".
  To attempt to debug this error, I tried the following</p>
  
  <pre><code> MyClassDBContext a = new MyClassDBContext("metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=user id=xxxx;password=xxxx;server=localhost;database=xxxx;connection timeout=30")
  </code></pre>
  
  <p>Now, I got an error saying "metadata keyword not supported". So I changed my code to</p>
  
  <pre><code>MyClassDBContext a = new MyClassDBContext("provider=System.Data.SqlClient;provider connection string=user id=xxxx;password=xxxx;server=localhost;database=xxxx;connection timeout=30")
  </code></pre>
  
  <p>Now I got an error saying "provider keyword not supported". So I again changed my code to</p>
  
  <pre><code> MyClassDBContext a = new MyClassDBContext("user id=xxxx;password=xxxx;server=localhost;database=xxxx;connection timeout=30")
  </code></pre>
  
  <p>and now it works!. My question is : how do I specify the provider and metadata at runtime? It looks like only the connection string is being accepted. I am using Entity 4.3.1 from Nuget.</p>
  
  <p>Thanks</p>