Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process SSAS tabular model from C#

So I've installed AMO and created the following console application:

using System;
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.Tabular;


namespace procesarCuboSSAST
{


    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string ConnectionString = "Data source=SERVER\\BI";


                using (Microsoft.AnalysisServices.Tabular.Server server = new Microsoft.AnalysisServices.Tabular.Server())
                {
                    server.Connect(ConnectionString);

                    Microsoft.AnalysisServices.Tabular.Database Db = server.Databases["TestModel"];     //Connect to the DB

                    Model m = Db.Model;


                  m.RequestRefresh(Microsoft.AnalysisServices.Tabular.RefreshType.Full);
                    m.SaveChanges();
                }
                Console.WriteLine("Press Enter to close this console window.");
                Console.ReadLine();



            }
            catch (Exception e)
            {
                Console.Write(e.Message.ToString());
                Console.WriteLine("Press Enter to close this console window.");
                Console.ReadLine();

            }
        }
    }
}

However, I'm getting error: "object reference not set to an instance of an object"

I can correctly list the databases and models in the SSAS instance with

 foreach (Database db in server.Databases) 
                { 
                    Console.WriteLine("Properties for database {0}:", db.Name); 
...

My server is SSAS 2014 Enterprise (tabular) (12.0.5000.0)

like image 977
Jack Casas Avatar asked Aug 16 '26 01:08

Jack Casas


1 Answers

What compatibility level is the Tabular model that you're attempting to process? The Model class is only for Tabular models at level 1200 or above. The Database class will let you view models at a lower compatibility level, but not modify them, which is why you can list the SSAS databases on the instance but not process them. The links below contain addition details on these classes.

Model Class

Database Class

like image 191
userfl89 Avatar answered Aug 18 '26 17:08

userfl89



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!