Solved

SSIS: Stop Package in Script Task

Posted on 2013-11-29
2
2,121 Views
Last Modified: 2016-02-11
Hi All,

I want to stop a package (I think the only way to do it is via script task) when the current package generates an error.

Anyway, I'm not familiar with VB that much and I found this method of stopping a package. I've tried to use it below
	Public Sub Main()
		'
		' Add your code here
        '
        Dim pkg As RunningPackage
        pkg.Stop()

		Dts.TaskResult = ScriptResults.Success
	End Sub

End Class

Open in new window


but I get an error message
Variable 'pkg' is used before it has been assigned a value. A null reference exception could result at runtime
.

Can anyone help me to write the correct syntax.

Thanks,

OS

-PS I'm using this within the On Error event handler.
0
Comment
Question by:onesegun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 39685670
>stop a package ... when the current package generates an error.
That should already be happening.  If the package throws a runtime error, it will execute anything found in that control/container/package's OnError property and exit.

Define what you mean be 'error'.
0
 

Author Comment

by:onesegun
ID: 39689916
Ah ok.

I'm using a Foreach Loop Container and a script task which counts the number of loops when the Foreach Loop container finds a file meeting the specific requirement.

http://microsoft-ssis.blogspot.co.uk/2012/06/stop-package-when-foreach-loop-does-not.html

But I guess what you are saying is that once the package fails by purposely returning a failure then there is no need to actually stop the package?

By the way do you know how I would write the syntax anyway if I actually wanted to stop a package executing based on some condition (i.e. not package failure).

Thanks....
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
My client sends a request to me that they want me to load data, which will be returned by Web Service APIs, and do some transformation before importing to database. In this article, I will provide an approach to load data with Web Service Task and X…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question