I am trying to connect to a Power BI Dataset hosted in Power BI Premium Workspace using below code. I don't have any issues in connecting to it when I use a SPN ID and a Secret, however when I try to use a Bearer token of the user I get below issue
Cubes = 'connection1.Cubes' threw an exception of type 'System.InvalidOperationException'
on the third last line (var connection1), My intent is to run a DMV query on the dataset and print the results in console. DMV query - 'Select * from $System.TMSCHEMA_TABLES'
using System;
using Microsoft.AnalysisServices.AdomdClient;
class Program
{
static void Main(string[] args)
{
string tenantId = "tenantId";
string workspaceName = "workspaceName";
string datasetName = "datasetName";
string accessToken = "abc" //Assume that I am able to get the bearer token programmatically
string xmlaEndpoint = $"https://api.powerbi.com/v1.0/{tenantId}/groups/{workspaceName}/datasets/{datasetName}/";
var connection1 = new AdomdConnection($"Data Source={xmlaEndpoint};User ID=;Password={accessToken};");
}
}
Cubes = 'connection1.Cubes' threw an exception of type 'System.InvalidOperationException'. Have validated the access token and it seems to be correct. I think I am doing something wrong with xmla endpoint.