Share via

How to query table from analysis server using Azure function hosted in azure

Jagmohan Singh Salaria 5 Reputation points
2025-10-09T17:49:29.51+00:00

Hi All,

I have azure function (net8.0 ) hosted in Linux and we want to query a table using XMLA like. Below is a sample code and getting error as Not found . Please note that I can't use Adomdconnection as it is not supported in Linux OS

string aasRegion = Environment.GetEnvironmentVariable("AAS_REGION");

       string aasServerName = "xyz";

       string databaseName = "abc";

       string tenantId = Environment.GetEnvironmentVariable("TENANT_ID");

       string clientId = Environment.GetEnvironmentVariable("CLIENT_ID");

       string clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");

string serverUrl = $"https://{aasRegion}.asazure.windows.net/{aasServerName}

string endpointUrl = $"{serverUrl}/webapi/xmla";

string xmlaQuery = $@"

<Execute xmlns=""urn:schemas-microsoft-com:xml-analysis"">

<Command>

<Statement>

  SELECTCOLUMNS (

    FILTER (

      student,

      student[id] = 5

    ),

    ""name"", student[name]

  )

</Statement>

</Command>

<Properties>

<PropertyList>

  <Catalog>abc</Catalog>

  <Format>Tabular</Format>

</PropertyList>

</Properties>

</Execute>";

var app = ConfidentialClientApplicationBuilder.Create(clientId)

               .WithClientSecret(clientSecret)

               .WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))

               .Build();

           string[] scopes = new string[] { $"https://{aasRegion}.asazure.windows.net/.default" };

           var authResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();

           string accessToken = authResult.AccessToken;

           

           // Prepare and send the HTTP request

           var request = new HttpRequestMessage(HttpMethod.Post, endpointUrl);

           request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

           request.Content = new StringContent(xmlaQuery);

           request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");

           

           var response = await httpClient.SendAsync(request);

           var responseContent = await response.Content.ReadAsStringAsync();

Azure Analysis Services

2 answers

Sort by: Most helpful
  1. Sai Uday Nagula 0 Reputation points
    2025-11-13T09:57:55.85+00:00

    Can anyone please share a whole working example.
    Thanks in advance.

    Note: am getting URL not found error.


  2. Anonymous
    2025-10-09T20:20:28.89+00:00

    Hi Jagmohan Singh Salaria,
    Welcome to the Microsoft Q&A.
    Thanks for your question. Since you're hosting the Azure Function on Linux, you’re right that AdomdConnection won’t work—it’s Windows-only. A good workaround is to use XMLA over HTTP, which lets you query Azure Analysis Services from any platform.

    Here’s how you can do it:

    1. Use MSAL to authenticate with Azure AD and get a bearer token for your service principal.
    2. Build your XMLA payload with a valid DAX query. For example:
         <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
           <Command>
             <Statement>
               EVALUATE
               SELECTCOLUMNS (
                 FILTER (
                   student,
                   student[id] = 5
                 ),
                 "name", student[name]
               )
             </Statement>
           </Command>
           <Properties>
             <PropertyList>
               <Catalog>abc</Catalog>
               <Format>Tabular</Format>
             </PropertyList>
           </Properties>
         </Execute>
      
    3. Send this payload to the AAS endpoint using HttpClient. Make sure you include the bearer token in the Authorization header and set the content type to text/xml.
    4. Also double-check that:
      • Your service principal has access to the AAS model.
      • The catalog name matches your database.
      • The endpoint URL is correct (should look like https://<region>.asazure.windows.net/<server>/webapi/xmla).

Your answer

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