我在 VB.NET 中创建了一个类库,我们从 SSIS 脚本任务调用它。
有人可以建议我如何从 VB.NET 函数中抛出错误,该函数应该返回一个字符串值,但它返回null,在这种情况下,我希望 SSIS 脚本任务失败。
如果从您的函数库中抛出任何异常/ Null,您可以使用以下代码使包失败。将 YourMethodCall() 替换为您的方法。
// For General exceptions
try
{
    // Your Method call
    var x = YourMethodCall();
    if (string.IsNullOrEmpty(x))
    {
        Dts.Events.FireError(0, "Your component Name", "Your Error Message", string.Empty, 0);
    }
    else
    {
        bool isFireAgain = false;
        Dts.Events.FireInformation(0, "You component Name", "Your Information for Successful run", string.Empty, 0, ref isFireAgain);
    }
}
catch (Exception ex)
{
    Dts.Events.FireError(0, "Your component Name", String.Format("Failed and Exception is : [{0}]",ex.Message), string.Empty, 0);
}
希望这可以帮助!