<?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 Re: connect to azure sql database from databricks using service principal in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36176#M26069</link>
    <description>&lt;P&gt;You can use, as an alternative, azure ad token in order to work (still with service principal).&lt;/P&gt;&lt;P&gt;Check attached.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2023 15:04:46 GMT</pubDate>
    <dc:creator>Alexkuva</dc:creator>
    <dc:date>2023-06-29T15:04:46Z</dc:date>
    <item>
      <title>connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36174#M26068</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me with the Python code to connect Azure SQL Database to Databricks using Service Principle instead of directly passing username and password.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJey_0-1688048752356.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2708i15EFAE2000DF0F44/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="DJey_0-1688048752356.png" alt="DJey_0-1688048752356.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJey_1-1688048784120.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2709iAD13C769C9E78D3A/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="DJey_1-1688048784120.png" alt="DJey_1-1688048784120.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm using above code but getting above error. Refer Screenshot 2.&lt;/P&gt;&lt;P&gt;Please help.&amp;nbsp;&lt;BR /&gt;Thanks!&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 14:28:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36174#M26068</guid>
      <dc:creator>DJey</dc:creator>
      <dc:date>2023-06-29T14:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36176#M26069</link>
      <description>&lt;P&gt;You can use, as an alternative, azure ad token in order to work (still with service principal).&lt;/P&gt;&lt;P&gt;Check attached.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 15:04:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36176#M26069</guid>
      <dc:creator>Alexkuva</dc:creator>
      <dc:date>2023-06-29T15:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36448#M26125</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/83645"&gt;@Alexkuva&lt;/a&gt;&amp;nbsp;Thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But as I can see in Py Documentation, "&lt;STRONG&gt;adal&lt;/STRONG&gt;" library will no longer receive any future improvements.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJey_0-1688100084736.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2715i9D9963ECF550AF1C/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="DJey_0-1688100084736.png" alt="DJey_0-1688100084736.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 04:41:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36448#M26125</guid>
      <dc:creator>DJey</dc:creator>
      <dc:date>2023-06-30T04:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36449#M26126</link>
      <description>&lt;P&gt;You can get the secrets using "&lt;SPAN&gt;dbutils.secrets.get" if you have azure key vault ready.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 05:01:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36449#M26126</guid>
      <dc:creator>berserkersap</dc:creator>
      <dc:date>2023-06-30T05:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36450#M26127</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/51953"&gt;@DJey&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;We haven't heard from you since the last response from &lt;/SPAN&gt;&lt;A href="https://community.databricks.com/s/profile/0053f000000WphkAAC" target="_blank"&gt;&lt;SPAN&gt;@Alexkuva&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;, and I was checking back to see if her suggestions helped you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Or else, If you have any solution, please share it with the community, as it can be helpful to others.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 05:22:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/36450#M26127</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-30T05:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/37388#M26339</link>
      <description>&lt;P&gt;You can use azure.identity instead and get the needed token&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 15:37:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/37388#M26339</guid>
      <dc:creator>Alexkuva</dc:creator>
      <dc:date>2023-07-11T15:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/45116#M27796</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/51953"&gt;@DJey&lt;/a&gt;&amp;nbsp; I think you can use this&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-migration" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-migration&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-acquire-cache-tokens" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-acquire-cache-tokens&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It seems now we need to use MSAL&lt;/P&gt;</description>
      <pubDate>Sat, 16 Sep 2023 15:42:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/45116#M27796</guid>
      <dc:creator>berserkersap</dc:creator>
      <dc:date>2023-09-16T15:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: connect to azure sql database from databricks using service principal</title>
      <link>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/45323#M27848</link>
      <description>&lt;P&gt;First, you need to create a service principal in Azure and grant it the necessary permissions to access your Azure SQL Database to do &lt;A href="https://www.globaldatabase.com/data-enrichment" target="_self"&gt;&lt;SPAN&gt;crm data enrichment&lt;/SPAN&gt;&lt;/A&gt;. You can do this using the Azure CLI or the Azure Portal. Ensure that your Databricks cluster has the necessary libraries installed. You will need to use the pyodbc library to connect to Azure SQL Database. You can install it using the following command in a Databricks notebook cell:&lt;/P&gt;&lt;P&gt;%pip install pyodbc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Python Code&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;Here's a Python code snippet to connect to Azure SQL Database using a Service Principal:&lt;/P&gt;&lt;P&gt;import pyodbc&lt;/P&gt;&lt;P&gt;# Define the connection string&lt;BR /&gt;server = "your_server_name.database.windows.net"&lt;BR /&gt;database = "your_database_name"&lt;BR /&gt;clientId = "your_service_principal_client_id"&lt;BR /&gt;clientSecret = "your_service_principal_client_secret"&lt;BR /&gt;authority = "&lt;A href="https://login.microsoftonline.com/your_tenant_id" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/your_tenant_id&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;connection_string = (&lt;BR /&gt;f"Driver={{ODBC Driver 17 for SQL Server}};"&lt;BR /&gt;f"Server={server};"&lt;BR /&gt;f"Database={database};"&lt;BR /&gt;f"Authentication=ActiveDirectoryServicePrincipal;"&lt;BR /&gt;f"UID={clientId};"&lt;BR /&gt;f"PWD={clientSecret};"&lt;BR /&gt;f"Encrypt=yes;"&lt;BR /&gt;f"TrustServerCertificate=no;"&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;# Establish the database connection&lt;BR /&gt;conn = pyodbc.connect(connection_string)&lt;BR /&gt;cursor = conn.cursor()&lt;/P&gt;&lt;P&gt;# Execute SQL queries here&lt;BR /&gt;cursor.execute("SELECT * FROM your_table_name")&lt;BR /&gt;rows = cursor.fetchall()&lt;/P&gt;&lt;P&gt;for row in rows:&lt;BR /&gt;print(row)&lt;/P&gt;&lt;P&gt;except Exception as e:&lt;BR /&gt;print(f"Error: {str(e)}")&lt;BR /&gt;finally:&lt;BR /&gt;# Close the connection&lt;BR /&gt;conn.close()&lt;/P&gt;&lt;P&gt;Replace your_server_name, your_database_name, your_service_principal_client_id, your_service_principal_client_secret, your_tenant_id, and your_table_name with your actual Azure SQL Database and Service Principal information.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2023 11:37:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/connect-to-azure-sql-database-from-databricks-using-service/m-p/45323#M27848</guid>
      <dc:creator>Joe_Suarez</dc:creator>
      <dc:date>2023-09-19T11:37:09Z</dc:date>
    </item>
  </channel>
</rss>

