<?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: Handling SQL database(PREVIEW) with notebook in SQL database</title>
    <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4353914#M136</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="903380" data-lia-user-login="munindra" class="lia-mention lia-mention-user"&gt;munindra&lt;/a&gt;&amp;nbsp;- Here is an example that one of our private preview customers got working in their notebooks:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def run_select_query(query_text):
    # Define JDBC URL and connection properties
    jdbc_url = "jdbc:sqlserver://&amp;lt;server&amp;gt;;" \
            "database=&amp;lt;db&amp;gt;;" \
            "encrypt=true;trustServerCertificate=false;authentication=ActiveDirectoryServicePrincipal;"

    connection_properties = {
        "user": f"{client_id}@{tenant_id}",
        "password": client_secret,
        "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    }

    # Define your SQL query
    query = query_text

    # Read data from Azure SQL Database using the query
    df = spark.read \
        .format("jdbc") \
        .option("url", jdbc_url) \
        .option("dbtable", query) \
        .option("user", connection_properties["user"]) \
        .option("password", connection_properties["password"]) \
        .option("driver", connection_properties["driver"]) \
        .load()

    # Show the data
    # df.show()
    return df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Please feel free to make it your own, including making sure it is safe to run in your environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The big thing you'll notice is that this requires an Entra Service Principal. That is the only option that will work right now.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2025 18:56:27 GMT</pubDate>
    <dc:creator>dlevy</dc:creator>
    <dc:date>2025-01-07T18:56:27Z</dc:date>
    <item>
      <title>Handling SQL database(PREVIEW) with notebook</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4347146#M118</link>
      <description>&lt;P&gt;I am trying to access the sql database inside the fabric using notebook with connection string but i am getting error&amp;nbsp;&lt;BR /&gt;('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 09:54:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4347146#M118</guid>
      <dc:creator>munindra</dc:creator>
      <dc:date>2024-12-31T09:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Handling SQL database(PREVIEW) with notebook</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4347940#M119</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="903380" data-lia-user-login="munindra" class="lia-mention lia-mention-user"&gt;munindra&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer to the following link to make sure that your format is right.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Data-Engineering/SQL-connection-with-Python/m-p/4154222" target="_blank"&gt;SQL connection with Python - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And please make sure that your server name and the username and the password is right, you can refer to the following link about the connection of database.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/database/sql/connect" target="_blank"&gt;Connect to your SQL database - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards!&lt;/P&gt;
&lt;P&gt;Yolo Zhu&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 02:36:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4347940#M119</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-02T02:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Handling SQL database(PREVIEW) with notebook</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4353914#M136</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="903380" data-lia-user-login="munindra" class="lia-mention lia-mention-user"&gt;munindra&lt;/a&gt;&amp;nbsp;- Here is an example that one of our private preview customers got working in their notebooks:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def run_select_query(query_text):
    # Define JDBC URL and connection properties
    jdbc_url = "jdbc:sqlserver://&amp;lt;server&amp;gt;;" \
            "database=&amp;lt;db&amp;gt;;" \
            "encrypt=true;trustServerCertificate=false;authentication=ActiveDirectoryServicePrincipal;"

    connection_properties = {
        "user": f"{client_id}@{tenant_id}",
        "password": client_secret,
        "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    }

    # Define your SQL query
    query = query_text

    # Read data from Azure SQL Database using the query
    df = spark.read \
        .format("jdbc") \
        .option("url", jdbc_url) \
        .option("dbtable", query) \
        .option("user", connection_properties["user"]) \
        .option("password", connection_properties["password"]) \
        .option("driver", connection_properties["driver"]) \
        .load()

    # Show the data
    # df.show()
    return df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Please feel free to make it your own, including making sure it is safe to run in your environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The big thing you'll notice is that this requires an Entra Service Principal. That is the only option that will work right now.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 18:56:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4353914#M136</guid>
      <dc:creator>dlevy</dc:creator>
      <dc:date>2025-01-07T18:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Handling SQL database(PREVIEW) with notebook</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4354369#M138</link>
      <description>&lt;P&gt;thanks for reply i am able to reslove my&amp;nbsp; error by changing authentication in my code to&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Authentication=ActiveDirectoryPassword&lt;BR /&gt;and if possible can you help me with building connection with lakehouse to vscode using python to get the files present inside the lakehouse .I am unable to find proper answer for this&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 08 Jan 2025 03:48:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4354369#M138</guid>
      <dc:creator>munindra</dc:creator>
      <dc:date>2025-01-08T03:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Handling SQL database(PREVIEW) with notebook</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4355689#M140</link>
      <description>&lt;P&gt;Have you seen this example?&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/fabric/onelake/onelake-access-python" target="_blank"&gt;Access OneLake with Python - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other angle would be to go through the SQL Analytics Endpoint. That will work just like a read-only SQL server so you should already have most of the code for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise, you may want to ask in the Lakehouse area.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 18:09:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/Handling-SQL-database-PREVIEW-with-notebook/m-p/4355689#M140</guid>
      <dc:creator>dlevy</dc:creator>
      <dc:date>2025-01-08T18:09:22Z</dc:date>
    </item>
  </channel>
</rss>

