[Python] PySpark to Azure SQL Database connection issue

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to connect to Azure SQL Database from Azure Synapse workspace Notebook using PySpark. Also I would like to use Active Directory integrated authentication. So what I've tried:

    jdbc_df = spark.read \
    .format("com.microsoft.sqlserver.jdbc.spark") \
    .option("url", "jdbc:sqlserver://my_server_name.database.windows.net:1433") \
    .option("database","my_db_name") \
    .option("dbtable", "my_table_or_query") \
    .option("authentication", "ActiveDirectoryIntegrated") \
    .option("encrypt", "true") \
    .option("hostNameInCertificate", "*.database.windows.net") \
    .load()


    Also I've tried the same way but in different syntax

    jdbcUrl = "jdbc:sqlserver://my_server_name.database.windows.net:1433;database=my_db_name;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;Authentication=ActiveDirectoryIntegrated"

    pushdown_query = "SELECT col1 FROM my_table_name"
    connectionProperties = {
    "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    }
    df = spark.read.jdbc(url=jdbcUrl, table=pushdown_query)
    display(df)


    And in both cases I get error


    IllegalArgumentException: KrbException: Cannot locate default realm
    ​

    What I'm doing wrong?

    Continue reading...

Compartilhe esta Página