1

我的代码在本地工作,连接字符串指向 AZURE SQL SERVER。但是,一旦我发布到 Azure 网站,每个带有 EF 模型的视图都会引发此错误。我已将“更改为”作为建议的解决方案之一,没有任何效果。我卡住了!!

  System.Data.EntityException: The underlying provider failed on ConnectionString. ---> System.ArgumentException: Keyword not supported: 'metadata'.
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
4

4 回答 4

2

如果您的连接字符串中有MultipleActiveResultSets=True,那么请将其删除,并且相同的连接字符串应该可以在 Windows Azure 中使用。我发现这是您遇到的最常见的错误。

如果不是这种情况,请发布您的连接字符串,我会看看。

于 2012-07-04T03:01:27.543 回答
2

我和 OP 有同样的问题,但他的解决方案对我不起作用。

这是一个连接字符串问题,但不是引号。

由于我花了两天时间解决,也许这对其他人有帮助:

在 Azure 上托管时适用于我的 ASP.NET MVC 4.5/Entity Framework 5.0 应用程序的连接字符串(我在本地针对 SQL Server 2012 进行开发,但将数据库迁移到 Azure SQL 数据库(使用SQL 数据库迁移向导))。我首先使用数据库来创建我的 .edmx 文件(我从数据库生成(数据)模型)]是:

<add name="MYPROJECTENTITIES" connectionString="**metadata=**res://*/MODELS.MYPROJECTMODEL.csdl|res://*/MODELS.MYPROJECTMODEL.ssdl|res://*/MODELS.MYPROJECTMODEL.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:B6JD5K5EP4.database.windows.net,1433;Initial Catalog=MYPROJECT_DB;Integrated Security=False;User ID=MYPROJECT@B6JD5K5EP4;Password=MYPASSWORDABC123;**MultipleActiveResultSets=True**;Encrypt=True;TrustServerCertificate=False&quot;" providerName="System.Data.EntityClient"/>

大写的文本是我的 Azure 信息。显然,您需要使用自己的。

连接字符串的这一部分给了我噩梦,它也可能导致您的问题:

res://*/Models.MyProjectModel.csdl|res://*/Models.MyProjectModel.ssdl|res://*/Models.MyProjectModel.msl

这些引用必须完全正确。让我重复一遍:那些参考必须完全正确!

After reading this article from 2008 ("Troubleshooting Entity Framework Connection Strings"), I used .NET Reflector to look inside the MyProjectModel.dll (the name of my .dll (likely different in your project) like he suggests and, sure enough, the connection string (that was generated automatically for me by the Entity Framework!) was wrong. It didn't include a prefix. As soon as I added Models. prefix (which is how the .csdl/.msl/.ssdl are named inside of my .dll (likely different in yours)), everything worked great. Have a look inside your .dll and see if the names match. If not, change them to match what appears in the .dll. (Read the article above if what I'm saying isn't clear enough.)

于 2012-12-29T04:09:05.723 回答
1

I had to change the connection string type to Custom in Azure portal.

enter image description here

于 2016-06-03T09:31:10.937 回答
0

Here is my answer on another SO thread that might be helpful. Steps I have mentioned there include an end-to-end configuration of connection string on Azure and dynamically using it. And yes, it fixes the error in question!

https://stackoverflow.com/a/37938912/3785895

More Info: Along with changing the providerName, there are a few extra bits we might need to check. Azure seems to be updating the web.config file after publishing the API App/Web App.

于 2016-06-21T20:44:32.043 回答