I'm having problems with EntityFramework (database first) and AppHarbor.
I am trying to use the configuration line as nested in the web.config from AppHarbor (I added metadata to the Sequelizer configuration parameter on the website), and I am trying to add some additional values using the code provided.
I am currently a very bad person and embed the string directly into the application configuration provider. It is not good if the hosting provider switches the DB to us, so I am looking to do it right and use AppHarbor values through web.config.
This is the line provided by AppHarbor (deleted passwords and server data):
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=<snip>;'
If used "as is", this generates the following error:
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.
Then I use the following code (postponed from one of the discussions on AppHarbor support) to add the necessary additional things that EF needs ...
if (String.IsNullOrWhiteSpace(ProductionDatabaseConnectionString))
{
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var connectionString = configuration.ConnectionStrings.ConnectionStrings["SQLAppHarbor001"].ConnectionString;
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;
This creates a connection string as follows:
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=<snip>;'MultipleActiveResultSets=True;App=EntityFramework;
But this causes an error:
Format of the initialization string does not conform to specification starting at index 165.
Index 165 is the beginning of a “provider connection string”.
The connection working string that I use is built-in, which currently works without problems:
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=<snip>;multipleactiveresultsets=True;App=EntityFramework'
The only real differences are that the entries "multipleactiveresultsets = True; App = EntityFramework" are inside the line "provider connection string" and not outside.
Other people seem to be using EntityFramework in AppHarbor, using the provided configuration options in order, so what am I doing wrong?