我的问题与 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/