Home > DTS > Stop DTS Package Execution Conditionally Without Failure

Stop DTS Package Execution Conditionally Without Failure

February 22nd, 2007 Leave a comment Go to comments

There is no straight way in DTS to stop the package on a certain condition without having it fail. Suppose in DTS package is suppose to be executed everyday at 8:00AM. This package is looking for a file c:\abc.txt. If the file has not arrived, it should gracefully stop without reporting any error. If the file has arrived then process the file and report success. This situation is handled by a bit of programming. Write down the following code in ActiveX Script Task.

Dim fso, file1Dim pkgSET pkg = DTSGlobalVariables.Parent

Set fso = CreateObject("Scripting.FileSystemObject")

IF (fso.FileExists("c:\abc.txt")) THEN	Msgbox "File exist. Continue"	pkg.Steps("DTSStep_DTSActiveScriptTask_2").DisableStep=False

	Set fso= Nothing

ELSE	Msgbox "Stop"	pkg.Steps("DTSStep_DTSActiveScriptTask_2").DisableStep=True END IFset pkg=nothingMain = DTSTaskExecResult_Success

What this does is disables the second step and hence the whole sequence of task is automatically disabled. so the Task1 will report success and DTS package execution will be completed without executing task 2 and onwards. You can download the dts package example and try to run it on your computer. It looks for file c:\abc.txt. If this file exists, it will run total 3 task with result SUCCESS. If the file is not found, it will run only Task1 with result SUCCESS.

Categories: DTS Tags:
  1. Wooballoo
    April 16th, 2007 at 04:10 | #1

    Fantastic – saved a lot of time!!!!

  2. Alan
    August 21st, 2007 at 07:46 | #2

    Thanks a lot, it’s perfect !

  3. Arthi
    November 13th, 2007 at 04:49 | #3

    Great!!! Big help to find this………

  4. Developer
    February 4th, 2008 at 05:03 | #4

    Perfect!Many thanks.. saved alot of time

  5. Jen
    October 6th, 2008 at 12:13 | #5

    This is perfect for my validation step.. Best.

  6. Jeff
    December 10th, 2008 at 15:09 | #6

    Thank you.

  7. January 11th, 2010 at 17:40 | #7

    Vishal.

    This is awesome. I have a peer trying it for days but could not do it. I surfed and came to your blog…BINGO.

    Thanks a ton

  8. kanthi
    January 22nd, 2010 at 02:51 | #8

    Thanks a lot Vishal. I have been searching about this for a long time.

  9. Anthony
    July 26th, 2010 at 09:22 | #9

    I can’t get this to work for me. I’m getting an error code:0, expected end of statement in the first line. Appreciate if someone can help or advise. I’m I missing something?

    Thanks.

  1. No trackbacks yet.