One colleague reported to me that the following code snippet (as it was being used by a customer) failed as explained in Connect -> AMO - ExecuteCaptureLog doesn't work with ErrorConfiguration:

 

namespace MySamples.SqlServer
{
    class Program
    {
        /// <param name="args">The Analysis Services server to connect to (as args[0]).</param>
        static void Main(string[] args)
        {

            {
                try
                {
                    Server server = new Server();
                    server.Connect("myServer\\myInstance");
                    try
                    {
                        Database db = null;
                        Cube cb = null;
                        db = server.Databases.FindByName("Foodmart2k");
                        {
                            Console.WriteLine("{0}", db.Name);
                            server.CaptureXml = true;
                            ErrorConfiguration ec = new ErrorConfiguration();
                            ec.KeyDuplicate = ErrorOption.ReportAndStop;
                            ec.KeyErrorLimit = 0;
                            ec.KeyNotFound = ErrorOption.ReportAndStop;
                            cb = db.Cubes.FindByName("HR");
                            cb.Process(ProcessType.ProcessFull, ec);
                            XmlaResultCollection results = server.ExecuteCaptureLog(true, true, true); 
                            foreach (XmlaResult result in results)
                            { 
                                foreach (XmlaMessage message in result.Messages)
                                {
                                    Console.WriteLine(message.Description );
                                }
                            }
                        }
                    }
                    finally
                    {
                        server.Disconnect();
                        server.Dispose();
                    }
                }
                catch (AmoException e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }
    }
}

 

And he also raised to my attention that SQL Server Management Studio was successfully doing what customer was trying to achieve (i.e. enumerating Errors and Warnings found during cube processing):

clip_image002

 

Now customer wanted to know how SSMS was circumventing this bug so that he could apply same workaround. What SSMS does is that it has some helper routines to build its own xmla which includes an ErrorConfiguration element, and then it invokes the Execute method passing that generated xmla.

 

So now we have to write a very specific, but simple, code snippet as a proof of concept:

 

namespace MySamples.SqlServer
{
    class Program
    { 
        public string MyHypotheticalHelperFunction()
        {
           return "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\"><ErrorConfiguration xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\"><KeyNotFound>ReportAndStop</KeyNotFound><KeyDuplicate>ReportAndStop</KeyDuplicate><NullKeyConvertedToUnknown>ReportAndStop</NullKeyConvertedToUnknown><NullKeyNotAllowed>ReportAndStop</NullKeyNotAllowed></ErrorConfiguration><Parallel><Process xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\"><Object><DatabaseID>Foodmart2k</DatabaseID><CubeID>HR</CubeID></Object><Type>ProcessFull</Type><WriteBackTableCreation>UseExisting</WriteBackTableCreation></Process></Parallel></Batch>"
        }

        /// <param name="args">The Analysis Services server to connect to (as args[0]).</param>
        static void Main(string[] args)
        {

            {
                try
                {
                    Server server = new Server();
                    server.Connect("myServer\\myInstance");
                    try
                    {
                        {
                            XmlaResultCollection results = server.Execute(MyHypotheticalHelperFunction()); 
                            foreach (XmlaResult result in results)
                            { 
                                foreach (XmlaMessage message in result.Messages)
                                {
                                    Console.WriteLine(message.Description );
                                }
                            }
                        }
                    }
                    finally
                    {
                        server.Disconnect();
                        server.Dispose();
                    }
                }
                catch (AmoException e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }
    }
}

 

This problem has been fixed in SQL Server 2008, but if you need this to work before it gets released, then use the workaround proposed here.

 

Check the XML for Analysis Services documentation for further information about the Batch, Process or all supported commands, or the ErrorConfiguration, Parallel, Object, TypeWriteBackTableCreation or all other supported properties.

 

Hope this post is useful to anyone.