When trying to connect to an Azure SQL database using Azure Data Studio, the connection failed with the following error message:
Login failed for user '<token-identified principal>'
I’m trying to connect using Azure Active Directory:
Although the error itself was not very clear to me, the error happened because the AAD user I’m using to connect does not exist as a user in the Azure SQL database.
To fix this, we need to create the user first. This can be done using the following command:
CREATE USER <Azure_AD_principal_name> FROM EXTERNAL PROVIDER;
After executing this command, you should be able to connect.
Of course, we still need to assign a specific role before we can do anything useful.
ALTER ROLE db_datareader ADD MEMBER <Azure_AD_principal_name>;