SSIS: Throwing errors from script task/component

本文介绍了一种在SSIS环境中捕获并记录从脚本任务或组件调用外部DLL时产生的错误的方法。通过递归遍历异常及其内部异常来获取详细错误信息,确保所有错误都能被日志系统捕获。

I'm working on a project at the moment that entails making calls to external DLLs from within a script task or script component. In our case the DLL in question is a web service proxy and we've been having numerous problems getting it to work. Being able to grab the errors returned from the WS has been a godsend and to do that I've come up with a bit of code that I thought might be worth sharing.

This is probably fairly noddy to any developers reading this but to those SSIS developers out there who are, like me, still trying to get their head around coding this could prove to be really useful.

All it basically does is catch an exception and recursively loop over any exceptions in the InnerException object(s), throwing out the error messags as error events as it goes. This means that the errors are caught in whatever logging mechanism you happen to be using.

Enough waffling. here's the code for within a script task - and before any developers start to moan at me for not using C# - you should know that VSA (which this is) only supports VB.Net:
 

Try
    'call a method
 which throws an error
Catch e
    Dts.Events.FireError(-1,
"", "Unable to solicit web service response: " + e.Message, ""
, 0)
    While Not e.InnerException Is Nothing

        e = e.InnerException
        Dts.Events.FireError(-1,
"", "InnerException: " + e.Message, ""
, 0)
    End While

End Try
 

The code to use inside a script component is almost identical:

Try
    'call a method
 which throws an error
Catch
    Me.ComponentMetadata.FireError(-1,
"", "Unable to solicit web service response: " + e.Message, "", true
)
    While Not e.InnerException Is Nothing

        e = e.InnerException 
        Me.ComponentMetadata.FireError(-1,
"", "InnerException: " + e.Message, "", true
)
    End While

End Try
 

All rather simple really. If you use this, let me know how it works for you. And if you have any better ideas - I'm all ears!

-Jamie

UPDATE

Thanks to Graham (see below) who pointed out that using the ToString() method of the exception will contain all of the InnerException messages.

Here's that code then:

Try
    'call a method
 which throws an error
Catch e
    Dts.Events.FireError(-1,
"", "Unable to solicit web service response: " + e.ToString(), ""
, 0)
End Try 

I haven't tested that yet but am assuming it works fine!

Thanks Graham!! Goes to show how little I know about .net dev doesn't it?

-Jamie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值