Welcome to EMC Consulting Blogs Sign in | Join | Help

SSIS Junkie

SSIS: Throwing errors from script task/component

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

 

Published Thursday, November 03, 2005 3:35 PM by jamie.thomson

Comments

 

Graham said:

If all you want is the message from the exception you can call ToString on the exception and any inner exceptions' Messages will be displayed too. So you can do something like the following and skip the while loop.

Me.ComponentMetadata.FireError(-1, "", "Unable to solicit web service response: " + e.ToString(), "")
November 3, 2005 9:44 PM
 

jamie.thomson said:

Now y'see...I didn't know that! Thanks Graham.

In this example I think I want to see all of my errors seperately but of course its your choice!

Learning...always learning.

Thanks!
November 3, 2005 9:49 PM
 

Franco said:

There is a simpler way to obtain all it , without to call the FireError function.

Place this code insted!   It will write also in the output in the same way FireError does!

" Throw New Exception("My message for the output / log ") "

;)

January 25, 2008 5:08 PM
New Comments to this post are disabled

This Blog

Syndication

Powered by Community Server (Personal Edition), by Telligent Systems