0

I'm successfully connecting to a Power BI Service instance to run commands from C# code using AdomdConnection and have problems connecting to the same Power BI Service instance with Microsoft.AnalysisServices.Tabular Server.Connect()

Server.Connect() from Microsoft.AnalysisServices.Tabular fails with:

  Session ID cannot be found. Either the session does not exist or it has already expired

What is the difference in how the two clients (ADOMD vs. TOM) handle the access token and the session? Does TOM require additional permissions in Azure? Why would this fail?

AdomdConnection that works:

string xmlaEndpoint = "powerbi://api.powerbi.com/v1.0/myorg/myworkspace";
string connectionString = $"Data Source={xmlaEndpoint};Catalog={datasetName}";
AdomdConnection connection = new AdomdConnection(connectionString);
DateTimeOffset expiration = DateTimeOffset.Parse(req.accessTokenExpiration);
connection.AccessToken = new Microsoft.AnalysisServices.AccessToken(req.accessToken, expiration);
connection.Open();

Microsoft.AnalysisServices.Tabular that fails:

string xmlaEndpoint = "powerbi://api.powerbi.com/v1.0/myorg/myworkspace";
var server = new Microsoft.AnalysisServices.Tabular.Server(); 
server.Connect(xmlaEndpoint, req.accessToken);

I'm generating the token using a Service Principal, not a user. I have Power BI Service PPU.

3
  • This might relate to how TOM validates sessions differently. Can you confirm if the dataset was created by the same Service Principal? Also, what scopes and resource were used when acquiring the token? Enabling logging or using Fiddler/Network Trace might reveal whether it's a session or token audience issue. Commented Jun 9 at 17:08
  • The token was created using the service principal, and the dataset was created by another user, but the service principal has admin permissions on the workspace Commented Jun 9 at 17:40
  • The second example that fails, you are passing the Data Source to the Connect methods' first parameter, but the first parameter is expecting a Connection String. Also you need to set the AccessToken property on the server. Commented Jun 10 at 13:16

1 Answer 1

0

When connecting to a Power BI workspace via the XMLA endpoint using Microsoft.AnalysisServices.Tabular.Server.Connect() (TOM), the connection can fail because TOM enforces stricter requirements on the access token especially the token's audience, structure, and permissions as compared to ADOMD.

What is the difference in how the two clients (ADOMD vs. TOM) handle the access token and the session? Does TOM require additional permissions in Azure?

Token handling:

ADOMD Accepts raw bearer token via .AccessToken property while TOM requires token audience to be correct. (Power BI resource)

Service Principal Compatibility:

ADOMD works as long as token has workspace access while for TOM token must be for Power BI resource.

Try the below mentioned steps to troubleshoot the issue:

Firstly, ensure your token must be acquired for this resource:

https://analysis.windows.net/powerbi/api

Check the below given Token Acquisition Code:

var tenantId = "<your-tenant-id>";
var clientId = "<your-client-id>";
var clientSecret = "<your-client-secret>";
var authority = $"https://login.microsoftonline.com/{tenantId}";

var app = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithClientSecret(clientSecret)
    .WithAuthority(new Uri(authority))
    .Build();

string[] scopes = new string[] { "https://analysis.windows.net/powerbi/api/.default" };

var result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
var accessToken = result.AccessToken;

Then use the Token in TOM that you've mentioned:

string xmlaEndpoint = "powerbi://api.powerbi.com/v1.0/myorg/myworkspace";
var server = new Microsoft.AnalysisServices.Tabular.Server();
server.Connect(xmlaEndpoint, accessToken); 

Lastly Add the Service Principal as Admin under Workspace Settings in Power BI: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.