Azure Analysis Service Tabular Model connecting to Power BI Service .NetCore Database.Model is null exception

550 views Asked by At

In a Azure Function I have connect to the power bi service and can get a dataset by using the FindByName or GetByName but the Database.Model value is null. Which means i cannot refresh the dataset or update anything.

While debugging can see all of the datasets in the workspace. any help gratefully recevie. thanks

using (Server as_server = new Microsoft.AnalysisServices.Tabular.Server())
{
    as_server.Connect(connectionString);
    Microsoft.AnalysisServices.Tabular.Database db = as_server.Databases.FindByName(database);
    Model m = db.Model;
    //my model m is allways null pointless to go on
}

I am using Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 19.9.0.1-Preview and Microsoft.AnalysisServices.NetCore.retail.amd64 19.9.0.1-Preview

1

There are 1 answers

1
naffy On BEST ANSWER

ok i have also had the pain of trying to get this to work in .net core with little documentation, i have no idea why the below works but here is the code to get a tabular model

using (Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server())
{
    server.Connect(connectionString);  
    Microsoft.AnalysisServices.Database database = server.Databases.GetByName("adventureworks");
    Microsoft.AnalysisServices.Tabular.Model  model = database.Model as Microsoft.AnalysisServices.Tabular.Model;
}

note that database.Model is null when you inspect it and if you use it directly like database.Model.Tables you get Object reference not set to an instance of an object for database.Model.get

however if you cast it, as i did in the last line of code suddenly is works!