Search code examples
c#sql-serverssasolapcube

How to stop SSAS cube processing programatically?


We are using Microsoft.AnalysisServices library to access our SSAS database (on SQL Server 2014) and programatically process cubes.

The code looks like this:

using (var server = new Server())
{
    server.Connect("someserver");

    if (server.Connected)
    {
        var db = server.Databases.FindByName("somedb");

        if (db != null)
        {
            db.Process(ProcessType.ProcessFull);
        }
    }
}

The problem is, full cube processing may take a long time (in our case over 1h). And we need a way to gracefully stop/cancel it if necessary (the code above is a part of complex Windows Service that sometimes needs to be restarted).

It is completely acceptable that interrupting the task results in cube not being processed.

Is there a way to write the code above so it is non-blocking? Or pass a callback somehow? I could not find anything relevant in MSDN documentation:

https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.database.aspx


Solution

  • Can you try getting rid of the using block and making your serverobject a class level member. Then try this on the cancel thread:

    server.CancelSession(server.SessionID);