I have an issue getting a DbContext
to correctly pull my connection string from my local.settings.json
Context:
- This is an Azure function project
- The main problem code is in
System.Data.Entity.Internal.AppConfig
- Although I have a
local.settings.json
file this is not dotnet core. It's .net 4.6.1
Error message:
'The connection string 'ShipBob_DevEntities' in the application's configuration file does not contain the required providerName attribute."'
Json configuration:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": ""
},
"ConnectionStrings": {
"ShipBob_DevEntities": {
"ConnectionString": "metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=***;initial catalog=***;persist security info=True;User Id=***;Password=***;;multipleactiveresultsets=True;application name=EntityFramework'",
"providerName": "System.Data.EntityClient"
}
}
}
Configuration versions tested:
- Moving the provider name into the actual
ConnectionString
token value : same error ocurrs
- Setting the
provider
attribute inside the ConnectionString
attribute to EntityClient
: this did nothing
Making ShipBob_DevEntities
a string value = to the value of ConnectionString
: this throws new errors the likes of which are
keyword metadata is not supported
I tried using an ADO connection string which throws a code first
exception which seems to occur when your connection string is incorrect in a database first
approach.
I've taken the liberty to decompile EntityFramework.dll
using dotPeek and have traced the problem down to System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig
. Inside this method there is a call to LazyInternalConnection.FindConnectionInConfig
which spits out a ConnectionStringSettings
object that has it's ProviderName
value set to null. Unfortunately I am unable to debug the AppConfig.cs
class which it seems to use to generate this value so I am stuck.
So far I have consulted these two articles. One of which states to put the provider name as it's own token; however, this is not working.
https://github.com/Azure/azure-functions-cli/issues/193
https://github.com/Azure/azure-functions-cli/issues/46
Does anyone know the correct format to use in local.settings.json for an Entity Framework connection?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…