Azure的发布数据库首先连接字符串不工作 [英] Azure Publish Database First Connection String Not Working

查看:140
本文介绍了Azure的发布数据库首先连接字符串不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过了步骤,首先使用数据库的蔚蓝门户网站发布我的web应用程序。

I have gone through the steps to publish my web app using database first on the azure portal.

然而,当我发表我收到此错误信息:

However, when I publish I get this error message:

code
  如果code首先使用模式最早开发可能无法正常工作。
  要继续使用数据库优先或模型优先保证实体
  框架连接字符串中的配置文件中指定
  执行的应用程序。使用这些类,从生成的
  数据库优先或模型首先,code首先添加任何附加
  使用属性或DbModelBuilder API,然后配置
  删除code抛出此异常。

Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.

在web.config中我的连接字符串后,它已被修改发布:

My connection string in the web.config after it has been modified by publish:

<add name="MySiteEntities" connectionString="metadata=res://*/MySite.csdl|res://*/MySite.ssdl|res://*/MySite.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:**********.database.windows.net,****;initial catalog=MySite;user id=username@**********;password=*******;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

(由EDMX生成)

我的背景:

My context (generated by edmx):

public partial class MySiteEntities : DbContext
{
    public MySiteEntities()
        : base("name=MySiteEntities")
    {
    }
...

我很困惑,原因是其看起来像实体框架是试图用code第一,而不是数据库第一。

I am very confused becuase it seems like entity framework is trying to use code first rather than database first.

更新:
我只是在本地使用相同的连接字符串尝试和Web应用程序看起来运行良好。 Web应用程序并连接到远程数据库的罚款。只有当我发布到Azure的失败。

UPDATE: I just tried using the same connection string locally and the web app seems to run fine. The web app does connect to the remote database fine. It is only when I publish to azure it fails.

推荐答案

阅读我的回答在一个类似的问题<一href=\"http://stackoverflow.com/questions/13840326/entity-framework-work-locally-but-not-on-azure/15858768\">Entity在本地而不是框架的工作在Azure上。

Read my answer to a similar question at Entity framework work locally but not on azure.

如果你犯了同样的错误我没有的,这是发生了什么......在Azure部署的应用程序无法找到您的连接字符串MySiteEntities你的web.config中。相反,当时您创建了Azure的网站(或其他云服务或),您创建了一个相关的Azure SQL数据库,并给了它的连接字符串完全相同的名称,MySiteEntities。后者的连接字符串没有型号/数据库一元数据引用一个普通的连接字符串,因此被视为由EF一个code-第一个连接,然后抱怨冲突。请参见 code首先与数据库首先获得这样的一个解释区别。

If you made the same "mistake" I did, this is what's happening ... the Azure-deployed app isn't finding your connection string "MySiteEntities" inside your web.config. Instead, at the time your created your Azure Web Site (or Cloud Service or whatever), you created an associated Azure SQL Database and gave its connection string the exact same name, "MySiteEntities". This latter connection string is a "plain" connection string without Model/Database-first metadata references, and so is being treated as a Code-First connection by EF, which then complains about the conflict. See Code First vs. Database First for an explanation of this distinction.

这篇关于Azure的发布数据库首先连接字符串不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆