cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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

 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.