gpt4 book ai didi

asp.net-mvc - 无法从应用程序连接到 SQL Azure,但可以从 SSMS 连接到 SQL Azure

转载 作者:行者123 更新时间:2023-12-03 18:17:28 25 4
gpt4 key购买 nike

我设置了一个 SQL Azure 实例,并且可以从 SQL Server Management Studio 连接到它,没有任何问题。但是,当我的应用程序尝试连接时,会发生此错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

我正在使用 Entity Framework Code First 4.1 和 ASP.NET MVC 3。我的应用程序最初是使用 SQL Express 成功开发的。现在我正在使用this tutorial to move the database to SQL Azure (该应用程序最终也将移至那里,但开发仍在继续)。

既然 SSMS 工作正常,我猜它归结为 web.config?我已经尝试了连接字符串名称的每种组合:

<connectionStrings>
<add name="ApplicationServices" connectionString="Server=tcp:suppressed.database.windows.net,1433;Database=EventsTest;User ID=suppressed;Password=suppressed;Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True;" providerName="System.Data.SqlClient" />
<add name="DomainContext" connectionString="Server=tcp:suppressed.database.windows.net,1433;Database=EventsTest;User ID=suppressed;Password=suppressed;Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True;" providerName="System.Data.SqlClient" />
<add name="Events.DataAccess.EntityFramework.DomainContext" connectionString="Server=tcp:suppressed.database.windows.net,1433;Database=EventsTest;User ID=suppressed;Password=suppressed;Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

我还尝试过 Wireshark,我对此知之甚少,但似乎建议进行一些事件(192.168.1.101 是我的计算机,207.46.63.13 是 SQL Azure 服务器):

1   0.000000    192.168.1.101   207.46.63.13    TCP [TCP segment of a reassembled PDU]2   0.116269    207.46.63.13    192.168.1.101   TCP ms-sql-s > bmc-net-adm [ACK] Seq=1 Ack=2 Win=8444 Len=03   2.091928    192.168.1.101   207.46.63.13    TCP [TCP segment of a reassembled PDU]4   2.209371    207.46.63.13    192.168.1.101   TCP ms-sql-s > kmscontrol [ACK] Seq=1 Ack=2 Win=5969 Len=05   2.352974    192.168.1.101   207.46.63.13    TCP [TCP segment of a reassembled PDU]6   2.469444    207.46.63.13    192.168.1.101   TCP ms-sql-s > vaultbase [ACK] Seq=1 Ack=2 Win=8625 Len=0

有什么想法可能会发生什么吗?

最佳答案

我加强了 DomainContext : DbContext 类中的调试,发现连接字符串始终指向 SQL Express,即使 web.config 中的所有条目都指向其他地方。然后我意识到问题出在构造函数中传递给基类的参数。

在这个过程中,我认为这个参数是要使用的数据库的名称。现在我意识到它是连接字符串条目的名称(或连接字符串本身)。

关于asp.net-mvc - 无法从应用程序连接到 SQL Azure,但可以从 SSMS 连接到 SQL Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6225303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com