cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from Azure SQL DB

AB_MN
New Contributor III

I am trying to read data into a dataframe from Azure SQL DB, using jdbc. Here is the code I am using.

driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
 
database_host = "server.database.windows.net"
database_port = "1433" 
database_name = "database"
table = "table1"
user = "user@abc.com"
password = "Passwrod123"
 
url = f"jdbc:sqlserver://{database_host}:{database_port};database={database_name};"
 
 
df = (spark.read
  .format("jdbc")
  .option("driver", driver)
  .option("url", url)
  .option("dbtable", table)
  .option("user", user)
  .option("password", password)
  .load()
)

Here is the error I am receiving:

com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open server "abc.com" requested by the login. The login failed.

The user does have permission to the server and database and can log in just fine using SSMS or Azure Data Studio. Is there some other configuration that I need to do so Databricks can talk to Azure SQL DB? What am I missing?

Thanks for the help.

1 ACCEPTED SOLUTION

Accepted Solutions

NakedSnake
New Contributor III

Hi there. Probably you also need to specify the correct authentication mechanism to get to the database. Try this one and check if it helps: https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentic...

View solution in original post

4 REPLIES 4

NakedSnake
New Contributor III

Hi there. Probably you also need to specify the correct authentication mechanism to get to the database. Try this one and check if it helps: https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentic...

Hi, I am facing the same error. I have my script as below. database is using Sql Server Authentication. I am not sure how to add the option of authentication. Also, I have a doubt that DB level also some permission is missing for the user login. Can you please guide.  

Upen_databricks_2-1696539350017.png

 

AB_MN
New Contributor III

That did the trick. Thank you!

Hi, I am facing the same error. I have my script as below. database is using Sql Server Authentication. I am not sure how to add the option of authentication. Also, I have a doubt that DB level also some permission is missing for the user login. Can you please guide.

Upen_databricks_0-1696539165225.png

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group