EF6 Connection String in Azure

馋奶兔 提交于 2019-12-07 01:30:38

问题


We have a website and a sql server on Azure. We have included the Entity Framework connection string in the Azure Portal but we get the following error: The connection string 'MyEntities' in the application's configuration file does not contain the required providerName attribute."

Looking at the connection string it clearly has the provider:

metadata=res:///MyEntities.csdl|res:///MyEntities.ssdl|res://*/MyEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:myserver.database.windows.net,1433;initial catalog=mydatabase;user id=user@myserver;password=PASSWRD;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"

so what is it asking for ? We also replace the " with normal quotes but we still get this error.

When using the same connection string in our development and connecting to the azure sql server everything works, but somehow the connection string we put in the portal that replaces the one in the web.config has problems.

Any help would be appreciated


回答1:


The portal doesn't have the capabilities to accept the providerName attribute. As such, you need to keep the connection string in your web.config, which specifies the name and the providerName but just put in a dummy value for the connection string. Now put that connection string value in the portal connection string. When it runs, it will pick up the providerName from the web.config, but then overwrite your dummy connection string that is in the web.config with the connection string value you put in Azure portal Application Settings [Connection Strings]. See SQL Azure EF Database First Connection String in Azure Management Portal




回答2:


Your missing the Provider Name on your Web.Config file. There are three attributes on your ConnectionStrings Add Element, Name, ConnectionString and ProviderName. Your are missing the ProviderName attribute on the Add Element. I spread out the attributes to show them clearly, Just add providerName="System.Data.EntityClient" after your connectionString attribute and you should be good to go !

 <connectionStrings>
        <add 

       name="XXXXXXContainer" 

       connectionString="metadata=res://*/XXXXXX.csdl|res://*/XXXXXX.ssdl|res://*/XXXXXX.msl;
       provider=System.Data.SqlClient;
       provider connection string=&quot;
       data source=chibitestdbserver.database.windows.net;
       initial catalog=XXXXXX;
       persist security info=True;
       user id=chibionos;
       password=XXXXXXXX;
       MultipleActiveResultSets=True;
       App=EntityFramework&quot;" 

      providerName="System.Data.EntityClient" />
      </connectionStrings>


来源:https://stackoverflow.com/questions/35120725/ef6-connection-string-in-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!