7

我有一个SQL Azure实例设置,并可以连接到它没有来自SQL Server Management Studio的问题。然而,当我的应用程序试图连接,出现此错误:无法连接到SQL Azure从应用程序,但可以从SSMS

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)

我使用实体框架代码第一次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=0 
3 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=0 
5 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 

任何想法可能发生了什么?

回答

1

我憋足了调试DomainContext : DbContext类中,发现连接字符串总是指向到SQL Express即使都在web.config中别处指向这些条目。然后我意识到问题是在构造函数中传递给基类的参数。

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

+0

这正是我造成麻烦的原因。谢谢。 – Kenci 2014-12-01 20:35:13

0

找到您的计算机的IP并在SQL Azure的防火墙中创建一条规则让其通过。它可能被阻止。

更多细节:

  1. 转到您的Azure的仪表板。

  2. 单击数据库

  3. 单击您的存储帐户,然后在DB服务器

  4. 单击防火墙规则,然后添加

  5. 只要把你的IP的IP范围的起始 IP范围完成

+0

我已经拥有了(幸运的是仪表板告诉你它是什么IP),我可以通过SSMS连接吗? – 2011-06-03 10:07:59

1

我设置我的连接离子字符串中显式实例化我的DbContext时:

public class DB: DbContext .. 

var databaseConnectionString = 
    "Server=tcp:private.database.windows.net;Database=privateDB;[email protected];Password=private;Trusted_Connection=False;Encrypt=True" 

var db = new DB(databaseConnectionString); 
相关问题