首页 文章

Azure中的EF6连接字符串

提问于
浏览
7

我们在Azure上有一个网站和一个SQL Server . 我们在Azure门户中包含了Entity Framework连接字符串,但是我们收到以下错误: The connection string 'MyEntities' in the application's configuration file does not contain the required providerName attribute."

查看连接字符串,它显然有提供者:

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"

那要求的是什么?我们还用正常引号替换 " 但我们仍然会收到此错误 .

当我们在开发中使用相同的连接字符串并连接到azure sql服务器时,一切正常,但不知何故,我们放在门户中的连接字符串替换了web.config中的连接字符串有问题 .

任何帮助,将不胜感激

2 回答

  • 2

    门户网站无法接受providerName属性 . 因此,您需要在web.config中保留连接字符串,该字符串指定名称和providerName,但只是为连接字符串添加虚拟值 . 现在将该连接字符串值放在门户连接字符串中 . 当它运行时,它将从web.config中获取providerName,但随后使用您在Azure门户应用程序设置[连接字符串]中放置的连接字符串值覆盖web.config中的虚拟连接字符串 . 见SQL Azure EF Database First Connection String in Azure Management Portal

  • -1

    您缺少Web.Config文件上的提供程序名称 . ConnectionStrings Add Element,Name,ConnectionString和ProviderName上有三个属性 . 您缺少添加元素上的ProviderName属性 . 我展开了属性以清楚地显示它们,只需在你的connectionString属性之后添加 providerName="System.Data.EntityClient" ,你应该好好去!

    <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>
    

相关问题