<?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: Persistent &amp;quot;Login Failed&amp;quot; using PySpark JDBC + Token Auth for Fabric SQL Database in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5179031#M16142</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1585402"&gt;@ackerman_chris&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2026 04:37:10 GMT</pubDate>
    <dc:creator>v-nmadadi-msft</dc:creator>
    <dc:date>2026-05-07T04:37:10Z</dc:date>
    <item>
      <title>Persistent "Login Failed" using PySpark JDBC + Token Auth for Fabric SQL Database</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5157159#M15983</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently writing a notebook in PySpark that is attempting to write data over to a new &lt;STRONG&gt;Microsoft Fabric SQL Database&lt;/STRONG&gt;. I’m trying to keep my ingestion logic strictly within &lt;STRONG&gt;Fabric Notebooks (PySpark)&lt;/STRONG&gt;, but I’ve hit a wall with the JDBC writer that I can't seem to get past.&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;The Goal&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;I am pulling data from a REST API into a Spark DataFrame and attempting to write it directly to a Fabric SQL Database. Using mode("append") so that Spark handles the CREATE TABLE DDL on the first run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;The Setup&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Identity:&lt;/STRONG&gt; Running the notebook manually under my Entra ID (for now).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Permissions:&lt;/STRONG&gt; I have verified my user exists in the SQL Database (sys.database_principals) and has been granted db_datawriter, db_datareader, and db_ddladmin roles.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Authentication:&lt;/STRONG&gt; I am fetching an access token via notebookutils and passing it into the JDBC properties.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Notebook Properties&lt;/STRONG&gt;: The notebook is using my user account as the &lt;STRONG&gt;Run As&amp;nbsp;&lt;/STRONG&gt;and is the owner as well.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;The Problem&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;Despite having the correct permissions and a valid token, the write operation consistently fails with:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open server "&amp;lt;REDACTED&amp;gt;" requested by the login. The login failed.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I have tried multiple token audiences, including "pbi" and "&lt;A href="https://database.windows.net/" target="_blank" rel="noopener"&gt;https://database.windows.net/&lt;/A&gt;", but the result is the same. The connection works fine for a spark.read, but the .write (which should trigger a DDL operation if the table is missing) triggers this login failure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Write data to Fabric SQL Database ─────────────────────────

if 'df' in locals() and not df.isEmpty():
    logger.info(f"Initiating write sequence for {schema}.{table_name}...")

    # 1. Fetch the SQL-specific token
    sql_token = notebookutils.credentials.getToken("pbi")
    
    write_props = {
        "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
        "accessToken": sql_token
    }
    
    jdbc_url = f"jdbc:sqlserver://{server_name}:1433;databaseName={database_id};"

    try:
        # 2. THE MAGIC LINE:
        # mode("append") checks if the table exists. 
        df.write.jdbc(
            url=jdbc_url,
            table=f"{schema}.{table_name}",
            mode="append", 
            properties=write_props
        )
        logger.info("Successfully wrote data. Table was created or appended automatically.")

    except Exception as e:
        # 3. Catching the 'First Run' Gremlin
        if "is not a valid schema" in str(e) or "Schema does not exist" in str(e):
            logger.error(f"FAIL: The schema '{schema}' doesn't exist.")
            logger.info(f"ACTION: Go to the SQL DB UI and run: CREATE SCHEMA {schema};")
        else:
            logger.error(f"Write failed: {str(e)}")
            raise e
else:
    logger.warning("No data retrieved from API. Skipping write.")&lt;/LI-CODE&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG&gt;What I've Checked&lt;/STRONG&gt;&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Verified the &lt;STRONG&gt;Server Endpoint&lt;/STRONG&gt; and &lt;STRONG&gt;Database GUID&lt;/STRONG&gt; are correct.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Confirmed the &lt;STRONG&gt;Schema&lt;/STRONG&gt; (traffic) was pre-created in the SQL DB.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Tried the standard .format("com.microsoft.sqlserver.jdbc.spark") which resulted in an AccessToken property conflict.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Verified that my user account &lt;STRONG&gt;can&lt;/STRONG&gt; connect and query via the SQL Database portal UI.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I found this Stack Overflow posting that had a similar issue and I wasn't able to resolve it from here&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/79704909/how-to-connect-to-fabric-sql-database-from-notebook" target="_blank" rel="noopener"&gt;python - How to connect to Fabric SQL database from Notebook? - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a specific driver property or a different token required for the Fabric SQL DB engine specifically when performing DDL/Write operations to a Fabric SQL Database?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight from someone who has this working in production would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2026 18:11:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5157159#M15983</guid>
      <dc:creator>ackerman_chris</dc:creator>
      <dc:date>2026-04-23T18:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Persistent "Login Failed" using PySpark JDBC + Token Auth for Fabric SQL Database</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5157210#M15984</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1585402"&gt;@ackerman_chris&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The best option is to use the Spark connector for SQL databases in Fabric - details in the Microsoft doc below:&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/spark-sql-connector?tabs=pyspark%2Caccesstoken" target="_blank"&gt;Spark connector for SQL databases - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please bear in mind this is still in Preview.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For getting the right connection string for your database, go to the Fabric SQL database in question, Settings &amp;gt; Connection Strings &amp;gt; JDBC. Remove "&lt;SPAN&gt;authentication=ActiveDirectoryInteractive" from the connection string. It should end with a ";". &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's a sample code:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import com.microsoft.sqlserver.jdbc.spark


data = [("Alice", 1), ("Bob", 2), ("Charlie", 3)]
cols = ["Name", "Age"]
df = spark.createDataFrame(data, cols)

# 2) JDBC URL for your Fabric SQL database
url = "jdbc:sqlserver://blah-blah.database.fabric.microsoft.com:1433;database={blah};encrypt=true;trustServerCertificate=false;" 


(df.write
   .mode("overwrite")                 # overwrite | append | errorifexists | ignore
   .option("url", url)
   .mssql("dbo.publicExample"))

#  3) Read it back to verify
spark.read.option("url", url).mssql("dbo.publicExample").show()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2026 18:49:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5157210#M15984</guid>
      <dc:creator>deborshi_nag</dc:creator>
      <dc:date>2026-04-23T18:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Persistent "Login Failed" using PySpark JDBC + Token Auth for Fabric SQL Database</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5159624#M16042</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1585402"&gt;@ackerman_chris&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2026 04:11:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5159624#M16042</guid>
      <dc:creator>v-nmadadi-msft</dc:creator>
      <dc:date>2026-04-28T04:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Persistent "Login Failed" using PySpark JDBC + Token Auth for Fabric SQL Database</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5179031#M16142</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1585402"&gt;@ackerman_chris&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2026 04:37:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Persistent-quot-Login-Failed-quot-using-PySpark-JDBC-Token-Auth/m-p/5179031#M16142</guid>
      <dc:creator>v-nmadadi-msft</dc:creator>
      <dc:date>2026-05-07T04:37:10Z</dc:date>
    </item>
  </channel>
</rss>

