Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityFramework, AppHarbor and configuration variables
    text
    copied!<p>I'm having some trouble with EntityFramework (database first) and AppHarbor.</p> <p>I'm trying to use the configuration string as inserted into the web.config by AppHarbor (I've added the metadata into the Sequelizer config option on the website), and I'm trying to add some additional values using code provided.</p> <p>Currently I'm being a very bad person and embedding the string directly into my apps configuration provider - not good if the hosting provider switch DBs on us, so I'm looking to do it the proper way and use the values AppHarbor supply via the web.config.</p> <p>This is the string as per provided by AppHarbor (passwords and server details removed):</p> <pre><code>metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=&lt;snip&gt;;' </code></pre> <p>If used "as is", that generates the following error:</p> <pre><code>The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource. </code></pre> <p>I then use the following code (purloined off of one of the AppHarbor support discussions) to append the required extra things EF needs...</p> <pre><code> if (String.IsNullOrWhiteSpace(ProductionDatabaseConnectionString)) { // Get it on first read and cache it var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); var connectionString = configuration.ConnectionStrings.ConnectionStrings["SQLAppHarbor001"].ConnectionString; // Add the required extra metadata for EF4.x if (!connectionString.Contains("MultipleActiveResultSets=True;")) connectionString += "MultipleActiveResultSets=True;"; if (!connectionString.Contains("App=EntityFramework;")) connectionString += "App=EntityFramework;"; configuration.ConnectionStrings.ConnectionStrings["SQLAppHarbor001"].ConnectionString = connectionString; configuration.Save(); ProductionDatabaseConnectionString = connectionString; } return ProductionDatabaseConnectionString; </code></pre> <p>That produces the connection string as follows:</p> <pre><code>metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=&lt;snip&gt;;'MultipleActiveResultSets=True;App=EntityFramework; </code></pre> <p>But that produces the error:</p> <pre><code>Format of the initialization string does not conform to specification starting at index 165. </code></pre> <p>Index 165 being the start of "provider connection string".</p> <p>The working connection string I use embedded, which currently works without issue, is:</p> <pre><code>metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=&lt;snip&gt;;multipleactiveresultsets=True;App=EntityFramework' </code></pre> <p>The only real differences being that the "multipleactiveresultsets=True;App=EntityFramework" entries are inside the "provider connection string" string rather than outside.</p> <p>Other people seem to be using EntityFramework on AppHarbor using the supplied configuration variables fine, so what an I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload