Connection refused error when trying to connect to an external service from Databricks

Check your DNS resolution and port connectivity, report to your internal networking team, and then contact Databricks if the issue still persists.

Written by parth.sundarka

Last published at: January 9th, 2025

Problem

When connecting Databricks to external services, such as an SQL server, Azure storage accounts, or Amazon RDS instances, you receive a Connection Refused error.

 

Cause

You may have a network misconfiguration, firewall restriction, or authentication error. 

With network misconfigurations, you may have incorrect subnets, route tables, or DNS settings that block communication with external services.

If your network firewall doesn’t include the external service on its access list, any attempt to connect may be refused.

 

Solution

Check your DNS resolution and port connectivity. If either or both of these checks fail, it confirms an issue related to any of the causes mentioned in the previous section, and requires communicating with your internal network team first. 

First, identify the service you are trying to connect to and get the hostname. 

 

Note

In a given URL, https://www.domainname.com the hostname is the domainname.com part. You must pass in only the hostname.

 

 

Check DNS resolution

Run the following command in a Databricks notebook using the same cluster specifications as when you faced the issue. 

 

%sh dig +short <your-hostname>

 

If the output is blank, DNS is not resolving the hostname, which can cause connection failures.

If you see an IP address, confirm that it matches the specific, expected IP address for the external service you are trying to connect to. 

Report connection failures or a mismatching IP address to your internal networking team.

 

Check port connectivity

Find the port number for the service you want to connect to and run the following command. Different services work on different port numbers, For example, the default port for the Azure SQL server is 1433.

 

%sh nc -vz <your-hostname> <port-number-to-check>

 

If you receive the response Connection to <your-hostname> port <port-number-to-check> (tcp) failed: Operation timed out, report this to your internal networking team. 

 

If you have verified with your internal networking team that DNS resolution and port connectivity are working, and still experience an issue, contact Databricks support. Include all command output screenshots when filing a ticket for more efficient issue resolution.