Question

I am using the following connection string to connect an Azure Web-Role to an instance of SQL running on a Virtual Machine. It's working fine!

<add key="VMConnectionString" value="Server=tcp:<mydomain>.cloudapp.net,1433;Database=myDatabase;User Id=myUserID;Password=**********;" />

My question is, should I be using the internal IP address of the VM (e.g. 10.1.0.0/16) instead of the public DNS to reduce latency? Do I need to put the web-role and the VM on the same virtual network in Azure? I tried to use the internal ip address of the VM as stated in the portal but it failed to connect, despite having port 1433 fully open. I should add that's without a Virtual Network.

Was it helpful?

Solution

I have now managed to reference the Virtual Machine running SQL Server with an internal IP 10.0.0.4 by first creating a Virtual Network in the Azure Portal and deploying a new VM to that network.

With the web-role you cannot specify virtual network settings on provisioning through the portal. So to bring the web-role into the network you need to define this in the .cscfg file:

<NetworkConfiguration>
  <VirtualNetworkSite name="VirtualNetworkName" />
  <AddressAssignments>
    <InstanceAddress roleName="MyWebRole">
      <Subnets>
        <Subnet name="AppSubnet" />
      </Subnets>
    </InstanceAddress>
  </AddressAssignments>
</NetworkConfiguration>

You can now determine the internal IP of the VM SQL Server in the portal and add this to the connection string defined in my application web.config. Publish your application to Azure and providing you've correctly configured the end points and opened the firewall it should work fine.

After running a few performance tests there is a margin gain to be had from using the internal IP over the public DNS. I recommend the guide connecting web roles to a VM as a good reference point.

One other thing. When using a DNS (e.g. myvm.cloudapp.net) in the connection string I could not find a predictable way to know which IP the web role would call from. It was therefore difficult to open port 1433 on the VM to just allow the web role through. With the internal IP I just opened up the whole subnet.

OTHER TIPS

Did you enable the endpoints for VM's in the portal? This is a simple operation as you just pick the port and the protocol. Here is an article that explains how:

http://www.windowsazure.com/en-us/manage/windows/how-to-guides/setup-endpoints/

I would also recommend that you use the A record, mydomain.cloudapp.net, instead of the vip as the vip may change when you redeploy. The vip will not change on reboot.

You would need to use the Public Virtual IP Address: Does Windows Azure offer static IP for VMs?

However I am going to ask, why are you installing your own instance of SQL server on a VM in Windows Azure and not using SQL Azure?

If you want to host your own SQL Server, at this stage I would recommend going with an Amazon EC2 instance as they have more features such as a permanent static IP. However you would also then need to transfer everything else over to the same data center as having a site hit a SQL Server across different data centers is really bad latency wise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top