Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Exiting a package without failure if no file exists Expand / Collapse
Author
Message
Posted Tuesday, June 3, 2014 3:27 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 7, 2014 7:49 AM
Points: 163, Visits: 831
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
Post #1576892
Posted Tuesday, June 3, 2014 3:32 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:23 AM
Points: 5,074, Visits: 11,852
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1576893
Posted Tuesday, June 3, 2014 4:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:05 AM
Points: 13,730, Visits: 10,683
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1576899
Posted Wednesday, June 4, 2014 7:54 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 7, 2014 7:49 AM
Points: 163, Visits: 831
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)
Post #1577338
Posted Wednesday, June 4, 2014 8:16 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:23 AM
Points: 5,074, Visits: 11,852
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1577353
Posted Wednesday, June 4, 2014 8:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 7, 2014 7:49 AM
Points: 163, Visits: 831
Cheers :)
Post #1577376
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse