I'm trying to get a website hosted on Azure IaaS VM to communicate with a database hosted on Azure PaaS SQL. However, I am receiving an exception when trying to connect:

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

From the VM itself, I can connect using SSMS to the server in question using its [name].database.windows.net host name with multiple users/passwords (copy/pasted from KeePass).

From the web app, the connection is configured using a connection string in a web.config. The connection string was copied/pasted from the Azure Portal and modified to contain the username and password (also copied/pasted from KeePass). As an additional test, I copied/pasted the connection string into the "Additional Connection Parameters" tab in SSMS's "Connect to Server" dialog, and was able to connect that way as well.

This is an "inside" to "inside" communication (https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-direct-route-ports-adonet-v12) and I added an allow rule in the Windows Firewall on the VM for the outbound transient SQL ports.

Can anyone suggest something that I may be overlooking to get this to work?

  • I'm a bit confused as well, because Azure SQL is supposed to be exclusively TCP, not named pipes. I have combed through the web.config, and there are no connection strings that use named pipes. – MichaelFStarke Mar 8 '17 at 20:56

How is the web app hosted - is this just within IIS? What type of Web App is it - .Net etc? What SQL Drivers do you have installed on the hosting VM?

  • Yes .NET 4.6.1, hosted on IIS. Default framework drivers for SQL Server. – MichaelFStarke Mar 9 '17 at 13:45
  • Ok. So if you haven't, ensure it's the latest SQL native client (2012). Also worth checking that you have the ADO.net SQL driver installed on there. Other than that, silly issues I've seen in the past is that the Windows environment variables don't have the path to the SQL drivers. – Jsmith_iii Mar 9 '17 at 13:52

The ultimate solution ended up being to nuke the existing VM and rebuild it from scratch. The new VM works flawlessly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.