.net - Azure SQL 数据库在本地运行时可以工作,但在发布到 Azure 时则无法工作

标签 .net azure ef-code-first asp.net-web-api entity-framework-5

我的问题与 this 非常相似SO 上有问题,但不完全是。

当我在本地连接到我的 azure 数据库时,它运行完美。但是当我部署到Azure时,它似乎无法连接到数据库。我首先使用 Entity Framework 5 代码,并且还在 EF 5 引用上设置了 copy local:true。

这些是我的连接字符串:

    <add name="api" connectionString="
    Server=tcp:[hidden].database.windows.net,1433;Database=API;
    User ID=[hidden]@[hidden];
    Password=[hidden];Trusted_Connection=False;
    Encrypt=True;Connection Timeout=30;
    PersistSecurityInfo=True;" providerName="System.Data.SqlClient" />

    <add name="Membership" connectionString="
    Server=tcp:[hidden].database.windows.net,1433;
    Database=Membership;User ID=[hidden]@[hidden];
    Password=[hidden];Trusted_Connection=False;
    Encrypt=True;Connection Timeout=30;
    PersistSecurityInfo=True;" providerName="System.Data.SqlClient"/>

我添加

    <customErrors mode="Off"/> 

在我的 web.config 文件中,这样我就可以看到堆栈跟踪,这些是我得到的异常:

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
[ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.

当读取堆栈跟踪时,可以肯定问题是我无法初始化成员数据库。这一定是 Azure 部署问题,但我似乎无法弄清楚..

编辑:

API 数据库现在正在运行,但成员资格给出了相同的错误。我将网站缩放为保留而不是共享。不知道会不会有影响。

已修复:

这很奇怪......突然该网站与两个数据库都建立了连接。没有执行任何其他操作将服务器从共享更改为保留..

最佳答案

检查 Windows Azure 门户上制定的 IP 规则,并确保您当前的 IP 地址在允许访问 Windows Azure 上运行的数据库的范围内

关于.net - Azure SQL 数据库在本地运行时可以工作,但在发布到 Azure 时则无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15274208/

相关文章:

c# - 如何从 WCF 服务应用程序获取客户端地址?

azure - 如何使用containerd将图像导入azure容器寄存器

c# - 在 .NET 4.0 基于代码的配置中使用 SQLite 的 EF6 : "Unable to Determine the DbProviderFactory"

asp.net-mvc - EF Core 中的 SQL Server 排序规则

.net - 使用 EF Code First 方法时的 MVC .Net 级联删除

c# - 程序集绑定(bind)重定向不起作用

c# - 如何限制 Winforms MaskedTextbox 中的值

c# - 如何获得指向 C 函数的指针?

android - 在 Android 上使用 MSAL 获取访问 token 来调用受 Azure AD 保护的 API 会出现 MsalDeclinedScopeException

node.js - "Hello-World"node.js/express 在本地工作,但不在 Azure Web App 上工作