Solved

SSIS: Stop Package in Script Task

Posted on 2013-11-29
2
2,230 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 66

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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