I am trying to issue an XMLA statement for "discover" to an Analysis Services Instance. Sending the XMLA from an XMLA window in Management Studio works fine and returns the desired result, so I am confident I got the basic syntax right.
Wraping it in an SQL Query (see below) it returns: "OLE DB provider "MSOLAP" for linked server "ANALYSIS" returned message "Das Discover-Element in Zeile 2, Spalte 58 (urn:schemas-microsoft-com:xml-analysis-Namespace) ist unter Envelope/Body/Execute/Command/Batch nicht zulässig."
Own Translation: "The Discover-Element in Row 2, Column 58 ... is under Envelope/Body/Execute/Command/Batch ... not allowed.".
I followed SSAS XMLA DISCOVER: how to get list of roles in SSAS database which has a working example and a screen shot included. That was 2010... so the version used there was most likely SQL 2008 or SQL 2008 R2. My code should be identical, yet it does not work (anymore?) on SQL 2012.
I even think this is correct, quoting from https://docs.microsoft.com/de-de/analysis-services/xmla/xml-elements-commands/batch-element-xmla?view=sql-analysis-services-2016: "Child elements (of Batch): Bindings, DataSource, DataSourceView, ErrorConfiguration, Parallel
One or more of the following XMLA commands: Alter, Backup, BeginTransaction, ClearCache, CommitTransaction, Create, Delete, DesignAggregations, Drop, Insert, Lock, MergePartitions, NotifyTableChange, Process, Restore, RollbackTransaction, SetPasswordEncryptionKey, Statement, Subscribe, Synchronize, Unlock, Update, UpdateCells"
"Discover" is not mentioned as a valid command there. It does not work without the Batch, too. I tested that of course. The error given above just changes to "is not allowed under Envelope/Body/Execute/Command"
So, any idea how this can be done?
DECLARE @xmla AS NVARCHAR(MAX) = '<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_METADATA</RequestType>
<Restrictions>
<RestrictionList xmlns="urn:schemas-microsoft-com:xml-analysis">
<DatabaseID>DBName</DatabaseID>
<CubeID>CubeName</CubeID>
<MeasureGroupID>MGName</MeasureGroupID>
</RestrictionList>
</Restrictions>
<Properties/>
</Discover>
</Batch>';
EXEC (@xmla) AT [ANALYSIS_LINKED_SERVER];