如何在Azure Function的应用程序设置中定义providername属性

2024-06-19

我正在尝试在我的 Azure 函数中建立实体框架数据库连接。因此我需要在函数的应用程序设置中定义一个连接字符串。仅在 Azure 门户中添加一个以我的 DbContext 类名作为键的连接字符串会导致异常,因为连接到数据库时,providername 属性未定义。我正在使用实体框架 v.6.2.0

例外是:

系统.InvalidOperationException: '应用程序配置文件中的连接字符串'CloudOrchestrationEntities'不包含所需的providerName属性。”'

有没有一种方法可以使用 json 字符串,就像我可以在 Azure 门户的应用程序设置中的 local.settings.json 中定义的字符串一样?

"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

我当然可以定义连接字符串作为通常的应用程序设置并在我的功能代码中检索它 https://stackoverflow.com/a/48152780/3218705连接到数据库但这不是我希望解决此问题的方式。实际上,我不想编辑自动生成的 EF 类,因为我与其他项目共享它们。


无法指定提供者名称System.Data.EntityClient仅在 Azure 上System.Data.SqlClient and MySql.Data.MySqlClient.

这个问题有一些解决方法和可能的解决方案调试 AzureFunction 以及部署 azure 函数时缺少 ProviderName https://stackoverflow.com/q/46698103/3234163

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在Azure Function的应用程序设置中定义providername属性 的相关文章

随机推荐