<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Connecting to Synapse database using AzureCliCredential token in Spark in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/connecting-to-synapse-database-using-azureclicredential-token-in/m-p/3534#M140</link>
    <description>&lt;P&gt;I want to connect to my Azure Synapse&amp;nbsp;database using Spark. I can do this in pyodbc no problem but that is not what I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is how I get my credentials&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;credential = AzureCliCredential()
databaseToken = credential.get_token('https://database.windows.net/')
&amp;nbsp;
# 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&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried this to see if it would work but I am obviously not doing this correctly. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;cambio_data_lake = '&amp;lt;synapse database&amp;gt;.sql.azuresynapse.net'
SQL_COPT_SS_ACCESS_TOKEN = '1256'
&amp;nbsp;
gauges_table = (spark.read
  .format("sqlserver")
  .option("host", cambio_data_lake)
  .option("port", "3342") # optional, can use default port 1433 if omitted
  .option("dbtable", "cambioinspection")
  .option(SQL_COPT_SS_ACCESS_TOKEN,tokenstruct)
  .load()
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there another approach for connecting using a token? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2023 20:30:15 GMT</pubDate>
    <dc:creator>PGrover</dc:creator>
    <dc:date>2023-06-06T20:30:15Z</dc:date>
    <item>
      <title>Connecting to Synapse database using AzureCliCredential token in Spark</title>
      <link>https://community.databricks.com/t5/machine-learning/connecting-to-synapse-database-using-azureclicredential-token-in/m-p/3534#M140</link>
      <description>&lt;P&gt;I want to connect to my Azure Synapse&amp;nbsp;database using Spark. I can do this in pyodbc no problem but that is not what I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is how I get my credentials&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;credential = AzureCliCredential()
databaseToken = credential.get_token('https://database.windows.net/')
&amp;nbsp;
# 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&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried this to see if it would work but I am obviously not doing this correctly. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;cambio_data_lake = '&amp;lt;synapse database&amp;gt;.sql.azuresynapse.net'
SQL_COPT_SS_ACCESS_TOKEN = '1256'
&amp;nbsp;
gauges_table = (spark.read
  .format("sqlserver")
  .option("host", cambio_data_lake)
  .option("port", "3342") # optional, can use default port 1433 if omitted
  .option("dbtable", "cambioinspection")
  .option(SQL_COPT_SS_ACCESS_TOKEN,tokenstruct)
  .load()
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there another approach for connecting using a token? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 20:30:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/connecting-to-synapse-database-using-azureclicredential-token-in/m-p/3534#M140</guid>
      <dc:creator>PGrover</dc:creator>
      <dc:date>2023-06-06T20:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Synapse database using AzureCliCredential token in Spark</title>
      <link>https://community.databricks.com/t5/machine-learning/connecting-to-synapse-database-using-azureclicredential-token-in/m-p/3536#M142</link>
      <description>&lt;P&gt;Hi @Patrick Grover​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We haven't heard from you since the last response from @Kaniz Fatma​&amp;nbsp;​, and I was checking back to see if her suggestions helped you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or else, If you have any solution, please share it with the community, as it can be helpful to others.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 06:20:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/connecting-to-synapse-database-using-azureclicredential-token-in/m-p/3536#M142</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-20T06:20:38Z</dc:date>
    </item>
  </channel>
</rss>

