SSIS: Throwing errors from script task/component

来源:互联网 发布:淘宝定制类目有多少家 编辑:程序博客网 时间:2024/05/04 22:37

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

原创粉丝点击