Skip to content
← Back to activity

Public problem

Azure Synapse Scala: MSI access token cant read from SQL pool table

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

In an Azure Synapse Scala notebook, connecting to a dedicated SQL pool with a system-assigned managed identity failed. The notebook used mssparkutils.credentials.getConnectionStringOrCreds("samplesqllink") to get an access token and passed it as the accessToken property to spark.read.jdbc. But reading the table threw a com.microsoft.sqlserver.jdbc error and no data came back.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

The token was fine, the SQL pool just didnt know the identity. You have to create a contained user for the Synapse workspace's managed identity in the database and grant it read access:

CREATE USER [jsynapse] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [jsynapse];
-- add db_datawriter too if the notebook writes back

(Replace jsynapse with your Synapse workspace name.) The reporter confirmed it worked right after adding the user. This step is easy to miss because the linked service and token setup all look correct without it.

Source: https://github.com/Azure-Samples/Synapse/issues/162

Source: https://github.com/Azure-Samples/Synapse/issues/162