Connect to Serverless SQL Pool using Synapse Notebook

Haoran Bai 80 Reputation points
2025-06-11T07:26:40.1766667+00:00

I'm trying to connect my database in serverless sql pool and create/drop some external tables in synapse notebook.

I'm using below to connect to the sql:

jdbc_url = "jdbc:sqlserver://synapse-haoran-test-ws-ondemand.sql.azuresynapse.net:1433;database=db_presentation;user=synapseadm@synapse-haoran-test-ws;password=MY_PASSWORD;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.sql.azuresynapse.net;loginTimeout=30;"

df = spark.read \
    .format("jdbc") \
    .option("url", jdbc_url) \
    .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
    .option("query", "SELECT * FROM [deliveries_db].[test]") \
    .option("fetchsize", "1000") \
    .option("integratedSecurity", "false") \
    .option("authenticationScheme", "NTLM") \
    .option("trustServerCertificate", "true") \
    .option("encrypt", "true") \
    .load()

df.show()

And I got below error when I run this code:

User's image

synapseadm is the admin user of my synapse workspace.

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,357 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Krupal Bandari 660 Reputation points Microsoft External Staff Moderator
    2025-06-11T09:42:53.63+00:00

    Hello @Haoran Bai
    The login error you're seeing:

    Cannot open database "db_presentation" requested by the login. The login failed.

    indicates that the user synapseadm@synapse-haoran-test-ws does not exist as a valid Azure Active Directory (AAD) principal in your Synapse workspace.

    To fix this:

    1. Please verify the exact Azure AD user or service principal name that your JDBC connection uses to authenticate.
    2. Then, run the following commands in the Serverless SQL pool (using Synapse Studio) to create that user in the db_presentation database and grant it read permissions:
    
    USE db_presentation;
    GO
    CREATE USER [<AAD_user_or_service_principal>] FROM EXTERNAL PROVIDER;
    GO
    ALTER ROLE db_datareader ADD MEMBER [<AAD_user_or_service_principal>];
    GO
    
    

    Replace <AAD_user_or_service_principal> with the exact Azure AD identity used by your connection (for example, ******@___domain.com or a service principal name).

    Once this is done, your Spark notebook connection should succeed without login errors.
    Reference:
    https://learn.microsoft.com/en-us/azure/synapse-analytics/security/how-to-set-up-access-control
    https://learn.microsoft.com/en-us/sql/t-sql/statements/create-user-transact-sql?view=azure-sqldw-latest
    https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-overview?view=azuresql
    https://stackoverflow.com/questions/78305589/how-to-grant-user-permission-to-a-specific-database-in-azure-synapse-analytics-l/78306259?utm_source=chatgpt.com
    If this is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.

    Let me know if you have any further Queries.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.