2

I am trying to establish an Entity Framework database connection within my Azure function. Therefore I need to define a connection string in the application settings of the function. Just adding a connection string with my DbContext class name as key in Azure Portal leads to an exception as the providername attribute is undefined when connecting to the database. I am using Entity Framework v. 6.2.0

The Exception is:

System.InvalidOperationException: 'The connection string 'CloudOrchestrationEntities' in the application's configuration file does not contain the required providerName attribute."'

Is there a way to use a json string like the one I can define in local.settings.json in the application settings in Azure portal?

"ConnectionStrings": {
"CloudOrchestrationEntities": {
  "ConnectionString": "metadata=res://*/CloudOrchestration.csdl|res://*/CloudOrchestration.ssdl|res://*/CloudOrchestration.msl;provider=System.Data.SqlClient;provider connection string='data source=*****.database.windows.net;initial catalog=*****;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework'",
  "ProviderName": "System.Data.EntityClient"
}
}

Using this json entry as connection string in Azure Portal including the provider name leads to an invalid connection string in my function code. enter image description here enter image description here

I surely can define the connection string as a usual app setting and retrieve it in my function code to connect to db but this is not the way I want this issue to be resolved. Actually I do not want to edit the auto generated EF classes as I share them with a different project.

Florian Grummel
  • 332
  • 3
  • 14
  • what is th exception you re having ? which version of entity framework are you using ? It seems you re using an old version of EF ? with code first your database connectionstring should be simpler – Thomas Jun 11 '18 at 11:54
  • I edited my question and added the exception message as well as the EF version that I use. – Florian Grummel Jun 12 '18 at 07:21
  • you connectionstring is the azure portal should be in the connectionstrings section. Also the name of your connectionstring should be `CloudOrchestrationEntities` and the value `metadata=res://*/CloudOrchestration.csdl|res://*/CloudOrchestration.ssdl|res://*/CloudOrchestration.msl;provider=System.Data.SqlClient;provider connection string='data source=*****.database.windows.net;initial catalog=*****;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework'` you dont want to include the json, just value – Thomas Jun 12 '18 at 08:04
  • Well actually you just copied the string that I posted above. This is exactly the setting that doesn't work as I didn't specify a providerName. Please read the post carefully as I describe this in the first paragraph. – Florian Grummel Jun 12 '18 at 12:17

1 Answers1

0

There is no way to specify the provider name to be System.Data.EntityClient on Azure, only System.Data.SqlClient and MySql.Data.MySqlClient.

There are some workarounds and possible solutions in this question Missing ProviderName when debugging AzureFunction as well as deploying azure function

ahmelsayed
  • 7,125
  • 3
  • 28
  • 40