How To Connect Remotely to SQL Server on an Azure Virtual Machine
This article explains what issues you might have when trying to connect to a SQL Server instance in an Azure VM and how to solve those issues.
Control access to SQL Server Azure VM
When creating your Azure VM, where you will install SQL Server, you need to also configure access. If you have had created the Azure VM in your Private Azure Cloud or if you don’t want to allow connections from other networks, then it isn’t recommended that you create SQL credentials to access your SQL Server databases, but if you need to allow it, you should keep the sa login disabled as it is very well known and often a target for malicious users.
On the other hand, if you created the Azure VM in the Public Azure Cloud and you need to access SQL Server remotely then you’ll need to create SQL Server credentials to access the SQL Server instance. Once more, it’s recommended to not enable the sa login.
If you didn’t configure the Azure SQL Server instance to allow SQL credentials you can configure it afterwards in the Azure Portal by selecting the Security option of your SQL virtual machine instance and Enable SQL Authentication.
If you want to provide a sysadmin role for a SQL credential, you can type the new login name and provide a respective password (if you don’t provide a password it will use the same password as the administrator user of the respective Azure VM).
Note that you can use the above screen to disable SQL Credentials.
Another option is to configure it by connecting to the SQL Server VM and in SSMS edit the SQL Server instance properties and in Security enable the SQL Server and Windows Authentication mode.
Restart the SQL Server service and then you can create SQL credentials to access the SQL Server instance databases.
Errors connecting to SQL Server
If you get the following error (i.e. 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 is correct and that SQL Server is configured to allow remote connections.) when trying to connect remotely to a SQL Server Azure instance
then in the Azure Portal check the security configuration for the respective SQL Server instance.
By default, a new SQL Server instance in Azure is configured for Private SQL connectivity (only let connections from the same Virtual Network connect to the SQL Server instance). Since we need to connect to it remotely from another network, we’ll need to change this configuration to Public (internet).
When changing this configuration, an automatic firewall rule is added for the Azure VM for this SQL Server instance. You can see that in the Azure VM Networking configuration.
TIP: You can edit this rule to add specific IPs for the machines that you want to allow to connect to this SQL Server instance.
Last Updated: 2020-03-24
About the author
View all my tips