In my case, since our client installed SQL Server on the VM, using a named database instance, the service which hosted the instance I needed to connect to didn't have its TCP port set properly. So my detail that the SQL Server instance was named was indeed important.
If you just cannot figure out why your Web Role (Cloud Service) just isn't connecting to your Virtual Machine in the same Virtual Network, In addition to checking all of the things above in the question, check the following setting:
- Log into the Virtual Machine (RDP)
- Open the SQL Server Configuration Manager
- Expand "SQL Server Network Configuration" in the left panel.
- Click on "Protocols for {SQL Instance name here}" in the left panel.
- Right-Click on "TCP/IP" in the right panel, go to "Properties..."
- Double check that "Enabled" is set to "Yes".
- Switch to the "IP Addresses" tab.
- At this point, you should see that the "TCP Port" should be 1433 for at least the domain IP (in my case 10.4.2.4 in the "IP2" section), if not "IPALL" or some others.
- Note that the "TCP Port" settings on all the "IP{X}" sections may have different values.
IF you don't see this SQL Server instance listening on 1433 (or some other port you are trying to configure):
- Go to "IPALL" and change the "TCP Port" to 1433 (or whatever port you like, 1433 is the default that things will send to).
- This will allow that port to be listened on for addresses coming to this server from anywhere.
- Note that there is probably a cleaner way to do this, but this worked quite well for us.
This allowed me to access the SQL Server instance from all the Cloud Services in that VNet, using only the Internal IP Address of the VM, without a public endpoint opened for the port I configured (1433).
Just in case, here is the working connection string:
<add name="ApplicationServices"
connectionString="Data Source=tcp:{VM Internal IP}\{InstanceName},{port};Initial Catalog={Table};User ID={username};Password={passwd};Encrypt=true;Trusted_Connection=false;TrustServerCertificate=true" providerName="System.Data.SqlClient"/>
Make sure you replace:
{VM Internal IP}
with your internal IP address{InstanceName}
with your SQL Server Instance's name, or leave it and the preceding\
out entirely if you have a default instance.{port}
should either be 1433 or whatever port you set open in your VM for that Sql Server instance.{Table}
with the Database table you want to use by default{username}
and{passwd}
with those for your SQL Server user. Note that I am using SQL Server authentication here.
It's also worth noting that this did not open my server up to the internet (as expected), as I still can't get at it from the outside world, so it remains secured within the VNet this way.
Hopefully this will help someone in the future.