Cannot connect to Azure SQL from application, but may from SSMS

I have an instance of SQL Azure and you can connect to it without problems in SQL Server Management Studio. However, when my application tries to connect, this error occurs:

A network or specific instance error occurred while creating a connection to SQL Server. The server was not found or was unavailable. Verify that the instance name is correct and that SQL Server is configured for a remote connection. (provider: SQL network Interfaces, error: 26 - Search error Specified server / instance)

I am using Entity Framework Code First 4.1 and ASP.NET MVC 3. My application was originally developed successfully using SQL Express. Now I use this tutorial to move the database to SQL Azure (the application will also move there, but development continues).

Since SSMS is working fine, I assume it comes down to web.config? I tried every combination of connection string name:

<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> 

I also tried Wireshark, which I know very little about, but seems to offer some activity (192.168.1.101 - my machine, 207.46.63.13 - SQL Azure server):

  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

Any ideas what could happen?

+7
source share
3 answers

I increased the debugging in the DomainContext : DbContext and found that the connection string always pointed to SQL Express, although all these entries in web.config were specified elsewhere. Then I realized that the problem was with the parameter passed to the base class in the constructor.

Somewhere along the line, I thought this parameter was the name of the database to be used. Now I understand that this is the name of the connection string entry (or the connection string itself).

+1
source

I set the connection string explicitly when creating the DBContext instance:

 public class DB: DbContext .. var databaseConnectionString = "Server=tcp:private.database.windows.net;Database=privateDB; UID=private@private ;Password=private;Trusted_Connection=False;Encrypt=True" var db = new DB(databaseConnectionString); 
+1
source

find the IP address of your computer and create a rule in the Azure SQL Firewall to get it through. It is probably blocked.

More details:

  • Go to the Azure toolbar.

  • Click "Database"

  • Click on your storage account and the database server

  • Click "Firewall Rules," then "Add."

  • Just enter the IP address as the beginning of the IP range and IP range

0
source

All Articles