Thursday 14 December 2023

Trying to refresh data model using pyadomd but getting namespace cannot appear under Envelope/Body/Execute/Command

I am using pyadomd to connect into azure analysis services and trying to refresh a data model. The connection is successful but getting the following error "namespace http://schemas.microsoft.com/analysisservices/2003/engine) cannot appear under Envelope/Body/Execute/Command". I am assuming i am doing the XMLA command incorrectly? could be the way i have structured the XMLA command? i think xmlns namespace could has been deprecated or no longer available? any help greatly appreciated since there's not much documentation on this. before i run the script i run az login using the azure-cli package so can authenticate locally. i am using python 3.8

full code script

from sys import path
from azure.identity import DefaultAzureCredential

# Add the path to the ADOMD.NET library
path.append('\\Program Files\\Microsoft.NET\\ADOMD.NET\\150')

# Import the Pyadomd module
from pyadomd import Pyadomd

# Set database and data source information
database_name = 'database_name'
data_source_suffix = 'data_source_suffix'
resource_uri = "https://uksouth.asazure.windows.net"
model_name = 'model_name'

# Get the access token using Azure Identity
credential = DefaultAzureCredential()
token = credential.get_token(resource_uri)
access_token = token.token

# Construct the connection string for Azure Analysis Services
conn_str = f'Provider=MSOLAP;Data Source=asazure://uksouth.asazure.windows.net/{data_source_suffix};Catalog={database_name};User ID=;Password={access_token};'

try:
    # Establish the connection to Azure Analysis Services
    with Pyadomd(conn_str) as conn:
        print("Connection established successfully.")
        # Create a cursor object
        with conn.cursor() as cursor:
            # XMLA command to refresh the entire model
            refresh_command = f"""
            <Refresh xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
                <Object>
                    <DatabaseID>{database_name}</DatabaseID>
                    <CubeID>{model_name}</CubeID>
                </Object>
                <Type>Full</Type>
            </Refresh>
            """

            # Execute the XMLA refresh command
            cursor.execute(refresh_command)
            print("Data model refresh initiated.")

except Exception as e:
    print(f"An error occurred: {e}")

full output

Connection established successfully.
An error occurred: The Refresh element at line 8, column 87 (namespace http://schemas.microsoft.com/analysisservices/2003/engine) cannot appear under Envelope/Body/Execute/Command.

Technical Details:
RootActivityId: 9f82c29d-f7dc-4438-a6a3-90b5ccef9818
Date (UTC): 12/12/2023 2:15:07 PM
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.IExecuteProvider.ExecuteTabular(CommandBehavior behavior, ICommandContentProvider contentProvider, AdomdPropertyCollection commandProperties, IDataParameterCollection parameters)
   at Microsoft.AnalysisServices.AdomdClient.AdomdCommand.ExecuteReader(CommandBehavior behavior)

the first link has information about namespace used and second link contains list of namespaces available.

https://learn.microsoft.com/en-us/analysis-services/multidimensional-models-scripting-language-assl-xmla/developing-with-xmla-in-analysis-services?view=asallproducts-allversions

https://learn.microsoft.com/en-us/openspecs/sql_server_protocols/ms-ssas/68a9475e-27d6-413a-9786-95bb19652b19

What i have tried

using alternative namespaces such as http://schemas.microsoft.com/analysisservices/2022/engine/922/922 http://schemas.microsoft.com/analysisservices/2019/engine http://schemas.microsoft.com/analysisservices/2012/engine

getting the same error so assuming its not the namespace.

tried using soap envelope format that didnt work either

refresh_command = f"""
            <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
                <Body>
                    <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
                        <Command>
                            <Refresh xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
                                <Type>Full</Type>
                                <Object>
                                    <DatabaseID>{database_name}</DatabaseID>
                                </Object>
                            </Refresh>
                        </Command>
                    </Execute>
                </Body>
            </Envelope>
            """


from Trying to refresh data model using pyadomd but getting namespace cannot appear under Envelope/Body/Execute/Command

No comments:

Post a Comment