Brian MacKay
Brian MacKay

Reputation: 32029

Connection string for SQL Server on an Azure VM

We migrated an application from physical servers to Azure VMs (one web server, one database server), and it's running great for the most part.

Last night there was an outage caused when the web server went offline for some TBD reason, and when it came back up the connection string started failing... The errors were all of the network path not found variety.

I know a VM's internal IPs can change inside my affinity group, but I'm not seeing a lot of straight answers on which IP or name I should be using.

Right now my connection string looks like this:

Server=MyDatabaseServerName;Database=xxxx;User ID=xxxx;Password=xxxx;

I feel like maybe MyDatabaseServerName was resolving wrong to the wrong IP for awhile there, and that maybe I should be using my cloudapp.net name instead, like this:

Server=xxx.cloudapp.net, 1433;Database=xxxx;User ID=xxxx;Password=xxxx;

...But I'm concerned that will go all the way out to the internet and back in.

So what's the safest way to go here?

Upvotes: 5

Views: 8348

Answers (1)

ProVega
ProVega

Reputation: 5914

The best thing to do is to create a Virtual Network and move your SQL Server(s) into it.

Then configure your cloud services to also join the same Virtual Network. This way your SQL server is NOT publically available and port 1433 is only available inside of the Azure network and more to the point your Virtual Network.

Then your connection string will look something like:

server=tcp:sql1prod.myvirtualnetwork.prod;User ID=user;Password=yourpassword

In our environment we have two subnets "Front" and "Back" - the cloud services join Front and our SQL cluster is in "Back".

Upvotes: 3

Related Questions