How to reliably retrieve Microsoft.AnalysisServices.Tabular objects after Tabular Database deployment in Power BI (Microsoft.AnalysisServices.Tabular)
Asked Answered
R

1

6

I am encountering a problem quite frequently in a console application (.NET Framework 4.7.2) that attempts to build and then deploy a Tabular Database to a Power BI workspace as a Semantic Model.

Whenever I try and retrieve the newly-added Database or access the Database's Model object I very frequently hit AmoExceptions or NullReferenceExceptions, especially if attempting to do so very soon after deploying the Database (even though I can see the Database through the PowerBI website).

I have been able to reduce the instability a little by coding in retry logic, but that seems untenable and unsustainable outside of a Dev environment.

For example, the (simplified) code below attempts to swap a temporary Database's Model with the Model of the standard (non-temporary) Database.

Here's my code:

// C# code
// Previous code to deploy Power BI database to PBI Workspace

Microsoft.AnalysisServices.Tabular.Server PBIServer = new Microsoft.AnalysisServices.Tabular.Server();
PBIServer.Connect(PowerBIConnectionString);

Microsoft.AnalysisServices.Tabular.Database tabularCubeFrom = PBIServer.Databases.FindByName(TabularCubeTemporaryName);
Microsoft.AnalysisServices.Tabular.Database tabularCubeTo = PBIServer.Databases.FindByName(TabularCubeName);

tabularCubeFrom.Model.CopyTo(tabularCubeTo.Model);

// Code to save changes, disconnect, etc.

Two similar errors are occurring in the code above (and related code):

  1. FindByName() not properly returning the Database soon after it is created (the Database can be seen in PowerBI)
  2. The Model object on the Database object not being populated (such as in the line calling CopyTo() above)

If I debug the issue and then retry the code after a slight delay, however, the Database and Model will be populated. Again, logic to retry the erroring code a few times after a slight delay reduces the instability but I don't believe that's a good "solution".

Is there a reliable way to ensure the Model object is fully loaded without special logic to retry after a delay?

Romaineromains answered 18/9, 2024 at 20:8 Comment(0)
H
1

It's not possible to fully eliminate the retry mechanism in this case. This issue happens even when deploying manually, so programmatically it wouldn't be any different.

The underlying problem is that the Power BI service takes time to propagate and make the newly created model available, and this delay can vary depending on various factors such as server load and your Power BI environment.

However, this issue can be mitigated depending on the version of Power BI you're using. For example, in a previous company I worked for, we experienced a noticeable improvement when we upgraded from Power BI Pro to Power BI Premium. The increased processing power in Power BI Premium had a direct impact on reducing the deployment time for models and databases, which helped alleviate issues like these.

In the meantime, implementing a retry or polling mechanism (as you're suggesting) is a reasonable solution to ensure the model is fully ready before proceeding.

Housecoat answered 8/10, 2024 at 13:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.