title: Changing the EF connection string gives - Keyword not supported: 'metadata'
body: <p>For the past few hours I've been looking into this problem, found many similar topics but none of them seems to help.</p>
  
  <p>I have a <code>C#</code> application that uses the <code>Entity Framework 5</code> and I have a <code>.edmx</code> data model that works fine when using the connection string from the app config file.</p>
  
  <p>Now I would like to change the connection string during runtime, but it throws an exception that says: </p>
  
  <blockquote>
    <p>Keyword not supported: 'metadata'.</p>
  </blockquote>
  
  <p>Here is the code that I have:</p>
  
  <pre><code>private string GetNewConnectionString(string server, string database, string username, string password)
  {
      var sqlBuilder = new SqlConnectionStringBuilder()
      {
          DataSource = server,
          InitialCatalog = database,
          UserID = username,
          Password = password,
          IntegratedSecurity = true,
          MultipleActiveResultSets = true
      };
  
      var entityBuilder = new EntityConnectionStringBuilder()
      {
          Provider = "System.Data.SqlClient",
          ProviderConnectionString = sqlBuilder.ToString(),
          Metadata = "res://*/MyTestModel.MyTestModel.csdl|res://*/MyTestModel.MyTestModel.ssdl|res://*/MyTestModel.MyTestModel.msl"
      };
  
      return entityBuilder.ToString();
  }
  
  public void insertInDB()
  {
      var newConnectionString = GetNewConnectionString(server, database, username, password);
      //newConnectionString = newConnectionString .Replace("\"", "&amp;quot;"); // doesn't help
      //newConnectionString = newConnectionString .Replace("\"", "'"); // doesn't help either
  
       using (var context = new MyTestModel.MyEntities(newConnectionString)) // it crashes here
       {
  
       }
   }
  </code></pre>
  
  <p>The metadata should be correct, because I have copied it from the app config file, also if I copy the value of <code>newConnectionString</code> to the app config and use it, it works fine if I replace the quotations with <code>&amp;quot;</code>.</p>
  
  <p>This is the value of <code>newConnectionString</code> (i've only replaced the credentials with some dummy credentials):</p>
  
  <blockquote>
    <p>metadata=res://<em>/MyTestModel.MyTestModel.csdl|res://</em>/MyTestModel.MyTestModel.ssdl|res://*/MyTestModel.MyTestModel.msl;provider=System.Data.SqlClient;provider
    connection string="Data Source=myServer;Initial
    Catalog=myDatabase;Integrated Security=True;User
    ID=myDbUser;Password=myDbUserPassword;MultipleActiveResultSets=True"</p>
  </blockquote>
  
  <p>I cannot see what is wrong with it, can anybody spot something?</p>