- Development
- git
Black Sand Solutions
Database First EF Connection Strings on Azure
- Azure
One of my clients has a website that uses the Entity Framework Database First approach. I've only ever used the Code First approach myself and came across a few gotchas in setting up an Azure site complete with SQL Azure.
Database First EF Connection Strings on Azure
This post describes each and it's associated resolution.
Format of the initialization string does not conform to specification starting at index X
The simplest and most obvious to fix and not necessarily related to the Database First approach.
In short, there is a problem with your connection string - most likely an illegal character at the index specified. The most common problem with copy and pasted connection strings is the presence of "
instead of "
o '
.
Database First Requires Metadata
I'm used to connection strings that look like this.
Note that this points to my local; I would overwrite this on Azure.
However, DatabaseFirst connection strings are a bit different and require extra information, they should look like this.
Note the inclusion of
metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;
If the connection string has the metadata, EF thinks it is Model First or Database First. If it is a plain connection string, EF thinks it is Code First.
The same string but updated to use a SQL Azure Server.
Keyword Not Supported metadata
The above connection string works perfectly when included in a web.config deployed to Azure. However if you attempt to use it from within the Azure Portal Connection Strings settings, it will fail with the following error:
Keyword Not Supported: metadata
The fix is simple; change the type from SQL Database to Custom
Configuration file does not contain the required providerName attribute
However, we are not out of the woods yet. The Connection Strings setting does not allow you to enter the provider name attribute and so you will get the following error at runtime:
The connection string 'MyEntities' in the application's configuration file does not contain the required providerName attribute."
The fix for this is to add a dummy string to your web.config, which includes the provider name attribute:
See Also
http://stackoverflow.com/questions/8618342/code-first-vs-database-first
http://stackoverflow.com/questions/13840326/entity-framework-work-locally-but-not-on-azure/15858768
http://stackoverflow.com/questions/36559467/sql-azure-ef-database-first-connection-string-in-azure-management-portal/36559729#36559729