连接字符串不适用于 Azure

Connectionstring doesn't work for Azure

我一直在寻找这个,但没有找到合适的答案。 这是关于我的 ASP.NET MVC 应用程序的 web.config 中的连接字符串 这是我的连接字符串:

<add name="DefaultConnection" connectionString="Server=tcp:****.database.windows.net,1433;Initial Catalog=***;Persist Security Info=False;User ID=****;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />

我还有第二个,效果很好:

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

它在本地主机上完美运行,但它不在线,(数据库和站点托管在 Azure 上)因此密码和用户名绝对正确。

我使用此连接字符串记录 in/register、注册、...

有什么问题?

非常感谢你们所有的救生员!

编辑:这是个例外: enter image description here

这些是我的防火墙设置:enter image description here

这可能是因为您没有为所有 Azure 连接打开防火墙。默认情况下,Azure 中的新 databases/server 没有添加防火墙规则。您可能已经添加了本地客户端 IP,但没有选中所有 Azure 连接的复选框。 https://docs.microsoft.com/en-us/azure/sql-database/sql-database-firewall-configure#overview 'Connecting from Azure' 部分应该指向正确的设置。

请注意,这允许所有源自 Azure 的 IP 连接到您的数据库。它不允许访问,因为您的身份验证机制将停止访问,但选中此选项后,将允许从 Azure 中的任何订阅进行连接。