尝试使用pyadomd刷新数据模型,但获取命名空间无法出现在Envelope/Body/Execute/Command下

问题描述 投票:0回答:1

我正在使用 pyadomd 连接到 azure 分析服务并尝试刷新数据模型。连接成功,但出现以下错误“命名空间 http://schemas.microsoft.com/analysisservices/2003/engine) 无法出现在 Envelope/Body/Execute/Command 下”。我假设我错误地执行了 XMLA 命令?可能是我构造 XMLA 命令的方式吗?我认为 xmlns 命名空间可能已被弃用或不再可用?非常感谢任何帮助,因为没有太多关于此的文档。在运行脚本之前,我使用 azure-cli 包运行 az login,以便可以在本地进行身份验证。我正在使用 python 3.8

完整代码脚本

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}")

全力输出

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)

第一个链接包含有关使用的命名空间的信息,第二个链接包含可用命名空间的列表。

https://learn.microsoft.com/en-us/analysis-services/multiDimension-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

我尝试过的事情

使用替代命名空间,例如 http://schemas.microsoft.com/analysisservices/2022/engine/922/922 http://schemas.microsoft.com/analysisservices/2019/engine http://schemas.microsoft.com/analysisservices/2012/engine

得到同样的错误,所以假设它不是命名空间。

尝试使用肥皂信封格式,但也不起作用

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>
            """
python azure xml-namespaces azure-analysis-services xmla
1个回答
0
投票

问题似乎出在 XMLA 命令的结构上,该命令的格式不适合 Azure Analysis Services。您应该为 Azure Analysis Services 使用正确的 XMLA 结构,包括适当的 SOAP 信封和命名空间。

试一试:

refresh_command = f"""
    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Header>
            <Session xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
                <SessionId></SessionId>
            </Session>
        </Header>
        <Body>
            <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
                <Command>
                    <Statement>
                        <Refresh xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
                            <Object>
                                <DatabaseID>{database_name}</DatabaseID>
                                <CubeID>{model_name}</CubeID>
                            </Object>
                            <Type>Full</Type>
                        </Refresh>
                    </Statement>
                </Command>
            </Execute>
        </Body>
    </Envelope>
"""
© www.soinside.com 2019 - 2024. All rights reserved.