【问题标题】:handle error on Microsoft.AnalysisServices update method处理 Microsoft.AnalysisServices 更新方法上的错误
【发布时间】:2018-12-12 23:49:30
【问题描述】:

我正在更新“数据源视图”中的维度定义。在 SSIS 脚本任务中使用 C# 代码执行此操作。 这是简化的 C# 代码:

DataSourceView ASDataSourceView;
//DataSourceView inherits from MajorObject
ASDataSourceView.Schema.Tables["DimTable"].ExtendedProperties["QueryDefinition"] = "SELECT * FROM ufc.TableWithData";
ASDataSourceView.Update();

我需要处理 Update() 方法期间可能出现的错误。 我认为使用 try catch 的通常方法会起作用,但似乎并非如此。 我需要以某种方式获取一个 xml 响应对象,然后检查它是否为空(无错误)或解析它并构建进一步的逻辑。

我试图阅读 Microsoft 文档,但不知道该怎么做。 XmlaWarningCollection Class

当我在 SSMS 中运行 update xml 语句时,我收到以下消息: 更新成功时:

<return xmlns="urn:schemas-microsoft-com:xml-analysis">
  <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty" />
</return>

当更新失败(由于语法错误而不是逻辑而失败,从模拟的角度来看也不是很正确):

XML 解析在第 9597 行第 63 列失败:元素结束标记中的名称必须与开始标记中的元素类型匹配。 运行完成

有人可以帮忙吗?

【问题讨论】:

    标签: c# sql-server error-handling ssis ssas


    【解决方案1】:

    我想我终于找到了解决方案:

    首先您需要启用 CaptureXML 选项;

    ServerName.CaptureXml = true;
    

    使用 XmlaResultCollection 选项第二次运行更新:

    UpdateOptions uo = default(UpdateOptions);
    UpdateMode om = default(UpdateMode);
    XmlaWarningCollection xm = null;
    ASDataSourceView.Update(uo, om, xm);
    

    第三次执行更新语句:

    XmlaResultCollection resultCollection = ServerName.ExecuteCaptureLog(false, false);
    

    之后我能够解析 resultCollection 对象:

    String ErrorMessages = String.Empty;
    
    if (resultCollection.ContainsErrors) {
                    ErrorMessages += $"Errors occured in cube {ConnectionString.CatalogName}:" + Environment.NewLine;
                    foreach (AS.XmlaResult result in resultCol) {
                        foreach (object error in result.Messages) {
                            if (error.GetType() == typeof(AS.XmlaError))
                                ErrorMessages += "ERR: " + ((AS.XmlaError)error).Description + Environment.NewLine;
                            else if (error.GetType() == typeof(AS.XmlaWarning))
                                ErrorMessages += "WARN: " + ((AS.XmlaWarning)error).Description + Environment.NewLine;
                        }
                    }
                    throw new Exception(ErrorMessages);
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 2017-11-03
      相关资源
      最近更新 更多