June 3, 2014 at 3:27 am
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
June 3, 2014 at 3:32 am
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.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 3, 2014 at 4:22 am
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.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 4, 2014 at 7:54 am
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)
June 4, 2014 at 8:16 am
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.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 4, 2014 at 8:45 am
Cheers 🙂
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply