User realm discovery failed from ADOMD

This is a short blog post to share a solution to the error "User realm discovery failed". This is a generic error when you authenticate in Azure Active Directory (AAD) from any application. In my scenario, we got this error when were trying to authenticate to Azure Analysis Services using ADOMD provider.

Here is the connection string we had in our code:

DataSource=asazure://westus.asazure.windows.net/tabularservername;Persist Security Info=True;User ID=internaldomain\serviceaccountname;Password=highlycomplexpassword

and we got this error:

User realm discovery failed. System: The remote server returned an error: (404) Not Found.

On the first thought, I thought this had to do with the version of analysis services binaries I was using since the support for AAD might not be available in older version of analysis services dll but that theory was ruled out when we tried the latest version of analysis services binaries and we still got the same error.

So, I tried to take a closer look at the error, this part of the error message "User realm discovery failed" gave a clue that AAD is unable to locate the service account we are using. So, we made a change to use the UPN format for the service account and viola, it worked!

So, here is how the connection string with UPN format will look like

DataSource=asazure://westus.asazure.windows.net/tabularservername;Persist Security Info=True;User ID=serviceaccountname@contoso.com;Password=highlycomplexpassword

Hope it helps!