title: Sending XMLA DISCOVER_XML_METADATA to SSAS from an SQL query
body: <p>I am trying to issue an XMLA statement for &quot;discover&quot; 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.</p>
  <p>Wraping it in an SQL Query (see below) it returns:
  &quot;<em>OLE DB provider &quot;MSOLAP&quot; for linked server &quot;ANALYSIS&quot; returned message &quot;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.</em>&quot;</p>
  <p>Own Translation: &quot;<em>The Discover-Element in Row 2, Column 58 ... is under Envelope/Body/Execute/Command/Batch ... not allowed.</em>&quot;.</p>
  <p>I followed <a href="https://stackoverflow.com/questions/62302170/ssas-xmla-discover-how-to-get-list-of-roles-in-ssas-database">SSAS XMLA DISCOVER: how to get list of roles in SSAS database</a> 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.</p>
  <p>I even think this is correct, quoting from <a href="https://docs.microsoft.com/de-de/analysis-services/xmla/xml-elements-commands/batch-element-xmla?view=sql-analysis-services-2016" rel="nofollow noreferrer">https://docs.microsoft.com/de-de/analysis-services/xmla/xml-elements-commands/batch-element-xmla?view=sql-analysis-services-2016</a>:
  &quot;<em>Child elements (of Batch):    Bindings, DataSource, DataSourceView, ErrorConfiguration, Parallel</em></p>
  <p><em>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</em>&quot;</p>
  <p>&quot;Discover&quot; 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 &quot;<em>is not allowed under Envelope/Body/Execute/Command</em>&quot;</p>
  <p>So, any idea how this can be done?</p>
  <pre><code>DECLARE @xmla AS NVARCHAR(MAX) = '&lt;Batch xmlns=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;&gt;
      &lt;Discover xmlns=&quot;urn:schemas-microsoft-com:xml-analysis&quot;&gt;
          &lt;RequestType&gt;DISCOVER_XML_METADATA&lt;/RequestType&gt;
          &lt;Restrictions&gt;
              &lt;RestrictionList xmlns=&quot;urn:schemas-microsoft-com:xml-analysis&quot;&gt;
                  &lt;DatabaseID&gt;DBName&lt;/DatabaseID&gt;
                  &lt;CubeID&gt;CubeName&lt;/CubeID&gt;
                  &lt;MeasureGroupID&gt;MGName&lt;/MeasureGroupID&gt;
              &lt;/RestrictionList&gt;
          &lt;/Restrictions&gt;
          &lt;Properties/&gt;
      &lt;/Discover&gt;
  &lt;/Batch&gt;';
  
  EXEC (@xmla) AT [ANALYSIS_LINKED_SERVER];
  </code></pre>