Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How to make a script component fail.

$
0
0

I'm posting this because I have seen 7 years of odd answers.

Posters have seen that ComponentMetadata.FireError() does not cause a script component (not script task) to abort.

This can be a serious challenge when the application detects a fatal error and needs to inhibit further processing. In my case the error is detected in the PreExecute() section of a data source script - the input file is not found.

I have come up with two solutions.

1) Use a flag to indicate the error has been detected (in PreExecute) by CreateNewOutputRows(). Something like:

Dim HaveError as boolean

sub PreExecute()

   HaveError = True

end sub

Sub CreateNewOutputRows()

  if HaveError then

     ComponenetMetadata.FireError(1, "Oops", "some message text", Nothing, 0, True)

  else

   ' do normal processing here

  end if

end sub

This causes the script component to fail. The code itself MUST skip any other processing. FireError does NOT cause a jump out of the code execution flow, even though OnError is fired.

2) Use Throw - this is a meat cleaver approach, but works

Sub PreExecute()

  If <condition> then

    Throw new Exception("Fatal error detected.....")

  else

  end if

end sub

The error is caught by OnError. Throw does cause a jump out of the code execution flow.

These techniques can be adapted to transform and destination type script components.

Good luck.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>