Exception when referencing SSAS Tabular model in C#

孤人 提交于 2019-12-07 16:25:27

问题


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://docs.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??


回答1:


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




回答2:


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

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

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



来源:https://stackoverflow.com/questions/44296949/exception-when-referencing-ssas-tabular-model-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!