Archive

Posts Tagged ‘captureXML’

Analysis Services captureXML and MaxParallel

November 24, 2014 Leave a comment

This is a quick post (mostly for me to remember).  Please no comments on any error handling.  This is just prototype code as it is.

The point is to show a method for inserting a maxParallel number into cube processing when using captureXML.  If you would like to see more about captureXML usage please refer to msdn

It can be used with AMO to execute nice programatic processing against cubes by connecting to the server and setting captureXML to true.  Then setting it to false when you are done.

The final step is to execute the log using the ExecuteCaptureLog command.  This does have a number of overloaded methods, but one is the second parameter which says if it should be done in parallel or not.  It does therefore not allow you to say, “I want to process this in parallel up to 16 threads” for example.

The only way I have found to do this is to add it to the log maunally.  This can be seen on line 14 in the code.  Once you are finished your amo work, you can then close the element, as seen on line 32.

Lastly, you can execture the ExecuteCapturelog as on line 38.  It is important to note that the first parameter is true, which is for batch (i.e. we want it to run as a batch).  the second parameter is for parallel, which is now set to FALSE.  This is important as we have chosen to take control of that element.

Server svr = new Server();
//make connection to cube server and throw error if connection is not complete
svr.Connect(cubeConnectionString);
if (svr.Equals(null)) { throw new Exception("Server: " + cubeServer + " not found";); }

//make connection to cube Database and throw error if not present
Database db = svr.Databases.FindByName(cubeDatabase);
if (db.Equals(null)) { throw new Exception("database:" + cubeDatabase + " not found";); }

//start capturing xmla from amo commands
svr.CaptureXml = true;

//set the maximum parallel manually as not possible through amo code.
svr.CaptureLog.Add("<Parallel MaxParallel=\"16\">);

//initiate a processFull on each dimension in the database
foreach (Dimension d in db.Dimensions)
{
    d.Process(ProcessType.ProcessFull);
}

//initiate a processfull on all measure groups in all cubes in the database
foreach (Cube cu in db.Cubes)
{
    foreach (MeasureGroup mg in cu.MeasureGroups)
    {
        mg.Process(ProcessType.ProcessFull);
    }
}

//Append the closing parallem element
svr.CaptureLog.Add("</Parallel>");

//stop capturing xmla
svr.CaptureXml = false;

//execute the xmla log in parallel
XmlaResultCollection results = svr.ExecuteCaptureLog(true, false);

foreach (XmlaResult result in results)
{
    foreach (XmlaMessage message in result.Messages)
    {
        if (message is XmlaError)
        {
            errorMessages += message.ToString() + System.Environment.NewLine;
        }
        else
        {
            messages += message.ToString() + System.Environment.NewLine;
        }
    }
}
svr.Disconnect();

 

If anyone finds an easier way to do this, please let me know Smile

Chris