Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Don-Bot
Helper V
Helper V

Create semantic model with ADO Command, unable to find model afterwards

I'm using the below code in C# .net with an ADO Connection to create a Semantic Model in the power bi service.  This code runs perfectly.   However, afterwards even though I can see the model in the workspace the "getbyname" command isn't working.  I've tried disconnecting and then reconnecting, disconnect, wait and reconnect to no avail.  

 

Is there a way to refresh the connection or something that would allow me to consistently see the model I have just created?

 using (AdomdConnection connection = new AdomdConnection($"DataSource={workspaceConnection};User ID=app:{ApplicationId}@{Tenant};Password={ApplicationSecret};"))
 {
     // Open the connection
     connection.Open();

     var command = connection.CreateCommand();
     command.CommandText = xmlaScript;
     command.ExecuteNonQuery();
     

 }
 server.Disconnect();
 server = ConnectToPowerBIAsServicePrincipal(workspaceName);


 Microsoft.AnalysisServices.Database database = server.Databases.GetByName(newDatabaseName);
                   

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Don-Bot 

Regarding your question, you can try the following code:

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;
}

Here's a screenshot of the response:

vlinyulumsft_0-1725949902114.png

 

Here are the relevant links, I hope you find it helpful:

 .net core - Azure Analysis Service Tabular Model connecting to Power BI Service .NetCore Database.Mo...


Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi, @Don-Bot 

Regarding your question, you can try the following code:

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;
}

Here's a screenshot of the response:

vlinyulumsft_0-1725949902114.png

 

Here are the relevant links, I hope you find it helpful:

 .net core - Azure Analysis Service Tabular Model connecting to Power BI Service .NetCore Database.Mo...


Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.