我和 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="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"" 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.)