Managed Identity Authentication from Synapse notebook using pyodbc library to Azure SQL DB
I have an Azure Synapse workspace and Azure SQL DB set up. What I'm trying to do is use python's pyodbc library to connect from an Azure Synapse notebook to a table in my Azure SQL DB using the managed identity of the Synapse workspace to authenticate. I've followed many instructions and I've tried a few different changes here and there, but I keep getting this same error:
Error: ('FA004', "[FA004] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Failed to authenticate the user '' in Active Directory (Authentication option is 'ActiveDirectoryMSI').\nError code 0xA190; state 41360\n (0) (SQLDriverConnect)")
I'm unsure why it is trying to use the user field when authentication type is set to MSI.
- I added the synapse workspace name associated to the synapse managed identity to my SQL DB as a user and I have added it roles.
- I created a security group with my alias and synapse msi to administrator for SQL server under Settings > Microsoft Entra ID then click set admin
- On SQL server I switched to system assigned managed identity under Security > Identity pane
I don't know if it is possible to use the synapse MSI directly, but assumed that since it is an MSI it would work. Below is some of the code I am using on the pyodbc side:
SERVER = 'tcp:<my_server_name>.database.windows.net'
DATABASE = '<my_db_name>'
DRIVER = '{ODBC Driver 18 for SQL Server}'
connectionString = f"Driver={DRIVER};Server={SERVER};Database={DATABASE};Authentication=ActiveDirectoryMsi;Connection Timeout=30;"
conn = pyodbc.connect(connectionString) #This is where it fails with above error.
How do I use the Synapse workspace managed identity to authenticate to Azure SQL DB? I haven't been able to find directions specifically for this scenario. I appreciate all your time and help in advance!