Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
Showing results for 
Search instead for 
Did you mean: 

Connecting to Synapse database using AzureCliCredential token in Spark

New Contributor II

I want to connect to my Azure Synapse database using Spark. I can do this in pyodbc no problem but that is not what I want.

Here is how I get my credentials

credential = AzureCliCredential()
databaseToken = credential.get_token('')
# get bytes from token obtained
tokenb = bytes(databaseToken[0], "UTF-8")
exptoken = b''
for i in tokenb:
 exptoken += bytes({i})
 exptoken += bytes(1)
tokenstruct = struct.pack("=i", len(exptoken)) + exptoken

I tried this to see if it would work but I am obviously not doing this correctly.

cambio_data_lake = '<synapse database>'
gauges_table = (
  .option("host", cambio_data_lake)
  .option("port", "3342") # optional, can use default port 1433 if omitted
  .option("dbtable", "cambioinspection")

Is there another approach for connecting using a token?



Community Manager
Community Manager

Hi @Patrick Grover​, you learn to create a Synapse workspace using the Azure CLI in this quickstart.

If you don't have an Azure subscription, create an Azure free account before you begin.

Not applicable

Hi @Patrick Grover​ 

We haven't heard from you since the last response from @Kaniz Fatma​ ​, and I was checking back to see if her suggestions helped you.

Or else, If you have any solution, please share it with the community, as it can be helpful to others. 

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!