【问题标题】:SSIS Conditional Split - force Default path to throw ExceptionSSIS Conditional Split - 强制默认路径抛出异常
【发布时间】:2013-08-14 15:25:04
【问题描述】:

我正在从“数据流”选项卡中的源读取数据。

数据经过条件拆分

订单 1 -> ColA = "Y"

订单 2 -> ColB = "Y"

如果默认输出条件被击中,既不是 ColA 也不是 ColB = "Y"... 那么我想抛出一个异常/错误,以便它击中 "Fail Component" 块。

【问题讨论】:

    标签: sql-server exception ssis default


    【解决方案1】:

    选择你的毒药并将其连接到默认输出。

    快速而肮脏的方法是附加派生列转换并强制除以零错误。

    我的偏好是路由到脚本组件。在脚本组件中,我将行的业务键作为 ReadOnly 传递。对于我看到的每一行,我都会引发一个警告事件,因此我记录了所有“坏”行。在 PostExecute 方法中,如果有任何行已发送到组件,然后我会引发 OnError 事件以强制数据流将错误报告回控制流。这将满足您对切换到“失败组件块”的控件的需求,并且您将在日志中获得足够的信息来研究臭鼬数据。

    您正在记录,对吗? (答案是肯定的。如果你没有做到的话:D)

    以下是我在查找失败时使用的代码。我的业务键是员工 ID 和生效日期,因此我将它们添加到 ProcessInput 方法中的列表中,然后在 PostExecute 中触发警告/错误。您可以轻松地在 ProcessInput 方法中引发警告,并在其中设置一个标志来指示 PostExecute 它需要出错。

    public class ScriptMain : UserComponent
    {
        List<KeyValuePair<string, string>> notFound;    
    
        public override void PreExecute()
        {
            base.PreExecute();
            notFound = new List<KeyValuePair<string, string>>();
        }
    
        public override void PostExecute()
        {
            base.PostExecute();
            foreach (KeyValuePair<string, string> kvp in notFound)
            {
                string msg = string.Format("Research->{0}:{1}", kvp.Key, kvp.Value);
                ComponentMetaData.FireWarning(0, "Unmatched Employees", msg, string.Empty, 0);
            }
    
            if (notFound.Count != 0)
            {
                bool cancel = true;
                ComponentMetaData.FireError(0, "SCR Lookup Employee", "Unmatched Employees found. See warning for more context", string.Empty, 0, out cancel);
            }
    
        }
    
    
        /// <param name="Row">The row that is currently passing through the component</param>
        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
            KeyValuePair<string, string> kvp = new KeyValuePair<string,string>(Row.EmployeeID, string.Format("{0:yyyy-MM-dd}", Row.EffectiveDT));
            notFound.Add(kvp);        
        }
    
    }
    

    【讨论】:

    • 有趣的是,没有内置的方法可以做到这一点......但这确实给了我一个前进的方向。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多