Andrae Gaeth
Andrae Gaeth

Reputation: 31

Exception when referencing SSAS Tabular model in C#

I am attempting to automate partition refreshes in Azure Analysis Services via C#. I have installed and referenced the latest 'Microsoft.AnalysisServices. ..' assemblies found here:

https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-data-providers.

I then have the following code:

using System; using Microsoft.AnalysisServices.Tabular;

    public void Run()
    {
        Server asSrv = new Server();

        try
        {

            asSrv.Connect(ASConnectionString);
            Database db = asSrv.Databases.FindByName("HospoIQTabular");
            Model m = db.Model;

            // only refresh 2017 partitions

            m.Tables["Sales"].Partitions["Sales - Post 2017"].RequestRefresh(RefreshType.Full);
            m.Tables["Payments"].Partitions["Payments - Post 2017"].RequestRefresh(RefreshType.Full);

            db.Model.SaveChanges();     // commit which will execute the refresh

        }
        catch (Exception e)
        {
            OnEventLog(e.Message);
        }
        finally
        {
            asSrv.Disconnect();
            asSrv = null;
        }

    }

Connect to the server and database itself works fine. However, attempting to reference 'db.Model' throws the following exception:

The value '2' is unexpected for type 'DataSourceType'.

I've looked but can't find any help anywhere on this. Any thoughts??

Upvotes: 3

Views: 1919

Answers (2)

Softcadbury
Softcadbury

Reputation: 33

The problem is similar with the NuGet package Microsoft.AnalysisServices.Tabular (v13)

Fortunately you can use the NuGet packages listed here: https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-data-providers.

In Visual Studio NuGet lists this package as Microsoft.AnalysisServices.retail.amd64

Upvotes: 2

Lior
Lior

Reputation: 41

For me, the path that worked was C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies but only after reading Andrae comment which sent me on the right direction

Upvotes: 1

Related Questions