SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Exiting a package without failure if no file exists


Exiting a package without failure if no file exists

Author
Message
Jake Shelton
Jake Shelton
SSC Veteran
SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)

Group: General Forum Members
Points: 291 Visits: 916
Hi all,

I'm converting the following Active X into VB Script, but I'm having difficulty working out how to get the script to stop all package execution if the file isn't found.

Cheers,

Jake

Dim oFSO
Dim sFileName
Dim pkg
Dim stpContinuePkg
Dim stpExitPkg

sFilename = "E:\SQLImport\Parts\TOC.txt"

'Set oFSO = CreateObject("Scripting.FileSystemObject")

' Check for file and return appropriate result
'If oFSO.FileExists(sFilename) Then
' Main = DTSStepScriptResult_ExecuteTask
'Else
' Main = DTSStepScriptResult_DontExecuteTask
'End If

'Set oFSO = Nothing

SET pkg = DTSGlobalVariables.Parent
SET stpContinuePkg = pkg.Steps("DTSStep_DTSExecuteSQLTask_1") 'spImportTOC

Set oFSO = CreateObject("Scripting.FileSystemObject")

'if file already exists
if oFSO.FileExists(sFilename) then
stpContinuePkg.DisableStep = False
else
stpContinuePkg.DisableStep = True
End If

Set oFSO = Nothing

' Whatever happens return SUCCESS so not to fail any calling jobs
Main = DTSTaskExecResult_Success
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18784 Visits: 20458
I suggest you change your approach slightly.

Create a FOREACH container which executes for every occurrence of the file you want to process. It will therefore execute either once or not at all.

Put your processing logic inside the FOREACH container.

The package will complete successfully and do nothing if the file is not found.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27655 Visits: 13268
Phil Parkin (6/3/2014)
I suggest you change your approach slightly.

Create a FOREACH container which executes for every occurrence of the file you want to process. It will therefore execute either once or not at all.

Put your processing logic inside the FOREACH container.

The package will complete successfully and do nothing if the file is not found.


+1 on this approach.
If you really want to use the script task, you can simply set a status in an SSIS variable. You can use this variable in a precedence constraint to the rest of the package.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Jake Shelton
Jake Shelton
SSC Veteran
SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)

Group: General Forum Members
Points: 291 Visits: 916
Phil Parkin (6/3/2014)
I suggest you change your approach slightly.

Create a FOREACH container which executes for every occurrence of the file you want to process. It will therefore execute either once or not at all.

Put your processing logic inside the FOREACH container.

The package will complete successfully and do nothing if the file is not found.


Ok, I've configured the container, but I'm not sure how it will know when to proceed to the next task or exiti the package. What elements need to go into it? I've got...

1) 'Check File Exists' - this is the script that looks for the file;

On success:
2) Generic Import Sproc - this imports data from any files found above.

On success moves to another sproc, but on failure..

3) Send FailMail (actually uses an 'execute SQL' task to have a SQL Server email out this message), if the file is there but cannot be imported, and I DO want to the package to fail if this is the case (Vs simply exiting gracefully if no files found)
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18784 Visits: 20458
Put everything that depends on the file's presence in the FEL container - so that appears to be all tasks.

Your file-existence-check script is rendered superfluous.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Jake Shelton
Jake Shelton
SSC Veteran
SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)SSC Veteran (291 reputation)

Group: General Forum Members
Points: 291 Visits: 916
Cheers Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search