title: How to create a valid connection string for Entity Framework - The underlying provider failed on Open?
body: <p>Given the following connection string:</p>
  
  <pre><code>&lt;add name="PrimaryDBConnectionString" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=10.1.1.101;Initial Catalog=primary;Persist Security Info=True;User ID=myuserid;Password=mypassword;MultipleActiveResultSets=True;Application Name=EntityFramework&amp;quot;" /&gt;
  </code></pre>
  
  <p>I attempt to open a connection in my DAL with the following:</p>
  
  <pre><code>        using (PrimaryDBContext ctx = new PrimaryDBContext(ConfigurationManager.ConnectionStrings["PrimaryDBConnectionString"].ToString()))
          {
              try
              {
                  ctx.Connection.Open();
                  var result = ctx.sq_newsfeed_GetProfileByID(profileID);
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>The underlying provider failed on Open</p>
  </blockquote>
  
  <p>I have messed around with the EF connection string and replaced all the provider prefix stuff with "metadata=res://*/;" but still no go.</p>
  
  <p>Can anyone shed some light on this please?</p>
  
  <p>Thanks.</p>
  
  <p>-- Update --</p>
  
  <p>Thank you for the response...
  I ended up just creating a new db connection from the UI and modifying the connection string to match my needs:</p>
  
  <pre><code>&lt;add name="PrimaryEntities" connectionString="metadata=res://*/PrimaryModel1.csdl|res://*/PrimaryModel1.ssdl|res://*/PrimaryModel1.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=10.99.108.42;initial catalog=primary;user id=dbuserID;password=somepw;multipleactiveresultsets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
  </code></pre>
  
  <p>I kept the metadata portion.  The trick was to ensure that your .csdl, .ssdl and .msl file name prefix matches your db context.</p>