Connecting SQL Server (on-premise) to Databricks via jdbc:sqlserver

Tico23
Contributor

Is it possible to connect to SQL Server on-premise (Not Azure) from Databricks?

I tried to ping my virtualbox VM (with Windows Server 2022) from within Databricks and the request timed out.

%sh
 
ping 122.138.0.14

This is what my connection might look like:

jdbcHostname = "122.138.0.14"
jdbcDatabase = "AdventureWorksDW2019"
username = "sa"
password = "AStrongPassword"
jdbcPort = 1433
 
jdbcUrl = "jdbc:sqlserver://{0}:{1};dabatabse={2};user={3};password={4}"\
            .format(jdbcHostname, jdbcPort, jdbcDatabase, username, password)

But when I tried to get data from my table:

df_product = spark.read.jdbc(url=jdbcUrl, table='DimProduct')
 
df_address.display()

I get the following error:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 122.138.0.14, port 1433 has failed. 
Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host 
and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".