首页 > 解决方案 > 配置文件不包含所需的 providerName 属性,Azure Api

问题描述

我做了一个天蓝色的网络应用程序。当我转到我的网络应用程序 URL 时,它说应用程序已启动并正在运行,https://nameofmyapp.azurewebsites.net/

当我尝试通过转到https://nameofmyapp.azurewebsites.net/api/Menus来发送对 Web API 的请求以获取 JSON 文本时,我收到此错误

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "The connection string 'PetSchedulerDbContext' in the application's configuration file does not contain the required providerName attribute.\"",
  "ExceptionType": "System.InvalidOperationException",
  "StackTrace": "   at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)\r\n 

这是我的连接字符串:

<connectionStrings>
    <add name="PetschedulerDbContext"  connectionString="Server=tcp:petschedulerserver.database.windows.net,1433;Initial Catalog=petschedulerdb;Persist Security Info=False;User ID=Julia;Password=Network5!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" /> 
  </connectionStrings>   

我尝试将提供者名称更改为

providerName="System.Data.EntityClient"

结果相同。我不明白所需的提供商名称是什么?如果您需要更多信息,请告诉我。

标签: azureapixamarinxamarin.formsdatabase-connection

解决方案


这是我对这个问题的美分:

先决条件:请确保您在 Azure 门户 Web 应用程序配置设置中也具有相同的连接字符串值集。

  • 如果您使用基于设计的方法,那么您需要定义设计器生成的连接字符串,它看起来像这样:

   <add name="Northwind_Entities"  
     connectionString="metadata=res://*/Northwind.csdl|  
                                res://*/Northwind.ssdl|  
                                res://*/Northwind.msl;  
                       provider=System.Data.SqlClient;  
                       provider connection string=  
                           &quot;Data Source=.\sqlexpress;  
                                 Initial Catalog=Northwind;  
                                 Integrated Security=True;  
                                 MultipleActiveResultSets=True&quot;"  
     providerName="System.Data.EntityClient"/>  

  • 如果您没有使用设计器(如果您没有 .edmx 文件),则连接字符串应如下所示:

<add name="ConnectionStringName"     providerName="System.Data.SqlClient"     connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True" />
附加参考:

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/connection-strings?redirectedfrom=MSDN

https://forums.asp.net/t/1858681.aspx?The+connection+string+EFDbContext+in+the+application+s+configuration+file+does+not+contain+the+required+providerName+attribute+

希望能帮助到你。


推荐阅读