This line:
WebSecurity.InitializeDatabaseConnection(connectionStringName: \"DefaultConnection\", userTableName: \"UserProfile\", userIdColumn: \"UserID\", us
Here's some code I use, to extract the database name & server name from a connection string.
Notice how it checks if it's an Entity Framework connection string, and if so, it extracts the "provider connection string" part of that, which can then be passed into SqlConnectionStringBuilder
:
If I didn't do this, I'd get that nasty "Keyword Not Supported: Metadata
" error.
if (connectionString.ToLower().StartsWith("metadata="))
{
System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(connectionString);
connectionString = efBuilder.ProviderConnectionString;
}
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
DatabaseServer = builder.DataSource; // eg "MikesServer"
DatabaseName = builder.InitialCatalog; // eg "Northwind"
An old post but my solution,
Unfortunately these didn't solve it for me using Azure Functions talking to a separate project (class library) with an EDMX.
I had to edit the Context.CS class constructor replacing the
: base ("Entities")
with
: base (ConfigurationManager.ConnectionStrings["Entities"].ConnectionString)
Hopefully this might help someone else in need.
For Azure Web App, Connection string type has not "System.Data.EntityClient", Custom works good.
For use in Azure Application Settings => Connection Strings:
If the connection string is generated by EF-designer be sure to replace &qout;
with "
in the string.
Check that provider=System.Data.SqlClient
Choose Type Custom in the dropdown
If the connection is for a model (Entity Framework) ensure that correct path to your model is used Ex: A model "MyWebRoot/Models/MyModel.edmx" is configured as: metadata=res:///Models.MyModel.csdl|res:///Models.MyModel.ssdl|res://*/Models.MyModel.msl;
When this happened to me it was because the connection string had:
providerName="System.Data.SqlClient"
but it should be:
providerName="System.Data.EntityClient"
because as was said by the other answer, it is an EF connection string.
The string you passed is not a valid database connection string, it's an EF connection string that contains a SQL Server connection string in its provider connection string
parameter. WebSecurity.InitializeDatabaseConnection expects a valid database connection string
To avoid parsing the connection string yourself, you can use the EntityConnectionStringBuilder class to parse the string and retrieve the database connection string from its ProviderConnectionString property