Package: Loop Import and Archive

Summary

Package properties

Auto Commit Transaction true
Creation date 2006-07-04T22:11:06.0000000+02:00
Creator computer name WORK
Creator name HOME\jose
Fail on error false
Max. concurrent steps 1
Transaction Isolation Level Cursor stability level
Use OLEDB Service Components true
Use transaction true
Write completion status to NT EventLog false

Package call tree (Loop Import and Archive)

Connections (Loop Import and Archive)

Connection name Data source Catalog User Connection description
SQLServerDestination(local)Pubs
Text File (Source)F:\Files\Copy (10) of Copy of Copy of Copy of Copy of Copy of File1.txt

(go to package (Loop Import and Archive) index)

Tasks (Loop Import and Archive)

DTSTask_DTSExecuteSQLTask_1 (Define Table)

Description Define Table
Connection 1 - SQLServerDestination
Timeout 0
SQL statement
IF OBJECT_ID('dtsloop') IS NULL

BEGIN

CREATE TABLE [dtsloop] (
[Col001] varchar (255) NULL, 
[Col002] varchar (255) NULL, 
[Col003] varchar (255) NULL )

END 

DTSTask_DTSActiveScriptTask_1 (DefineTheGVs)

Description DefineTheGVs
Function name Main
Script language VBScript
ActiveX script
' 246 (DefineTheGVs)
Option Explicit

Function Main()

	dim fso
	dim fold
	dim pkg
	dim stpContinuePkg
	dim stpExitbadDirectory

	' First thing we need to do is to check if our directories are valid.

	SET pkg = DTSGlobalVariables.Parent

	SET stpContinuePkg = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
	SET stpExitBadDirectory = pkg.Steps("DTSStep_DTSActiveScriptTask_2")
	
	DTSGlobalVariables("gv_FileCheckErrors").Value = ""

	'We use the FileSystemObject to do our
	'Folder manipulation

	set fso = CREATEOBJECT("Scripting.FileSystemObject")


	'Here we check to make sure the Source folder for the files exists

	if fso.FolderExists(DTSGlobalVariables("gv_FileLocation").Value) <>  "True" then
	DTSGlobalVariables("gv_FileCheckErrors").Value = CSTR(DTSGlobalVariables("gv_FileCheckErrors").Value) &_
		 " " & "Source File directory Not Found"
	end if

	'Here we check to make sure the Archive folder for the files exists

	if fso.FolderExists(DTSGlobalVariables("gv_ArchiveLocation").Value)  <>  "True" then
	DTSGlobalVariables("gv_FileCheckErrors").Value = CSTR(DTSGlobalVariables("gv_FileCheckErrors").Value) &_
		 " " & "Archive File directory Not Found"
	end if

	'We predefined the GlobalVariable gv_FileCheckErrors = "" which
	'has a length of 2 so we check to see if it has expanded.  If it has then we
	'know we had an error and we disable the step that would
	'allow us to continue in the package and enable the step
	'that takes us out and handles the errors we encountered

	If len(DTSGlobalVariables("gv_FileCheckErrors").Value)  > 2 Then
		stpContinuePkg.DisableStep = True
		stpExitBadDirectory.DisableStep = False
	Else
		stpContinuePkg.DisableStep = False
		stpExitBadDirectory.DisableStep = True

	end if

	Main = DTSTaskExecResult_Success
End Function

DTSTask_DTSActiveScriptTask_2 (Bad Directories)

Description Bad Directories
Function name Main
Script language VBScript
ActiveX script
' 246 (Bad Directories)
Option Explicit

Function Main()

	Msgbox "You had a Bad Direcory or two please consult: " &_
	DTSGlobalVariables("gv_FileCheckErrors").Value

	Main = DTSTaskExecResult_Success
End Function

DTSTask_DTSActiveScriptTask_3 (Begin Loop)

Description Begin Loop
Function name Main
Script language VBScript
ActiveX script
' 246 (Begin Loop)
Option Explicit

Function Main()

	dim pkg
	dim  conTextFile 
	dim stpEnterLoop
	dim stpFinished

	set pkg = DTSGlobalVariables.Parent
	set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
	set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
	set conTextFile = pkg.Connections("Text File (Source)")

	' We want to continue with the loop only of there are more
	' than 1 text file in the directory.  If the function ShouldILoop
	' returns true then we disable the step that takes us out of the package
	' and continue processing

	if ShouldILoop = True then
		stpEnterLoop.DisableStep = False
		stpFinished.DisableStep = True
		conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
		stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
	else
		stpEnterLoop.DisableStep =True
		stpFinished.DisableStep = False
		stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
	End if

	Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

	dim fso
	dim fil	
	dim fold 
	dim pkg
	dim counter

	
	set pkg = DTSGlobalVariables.Parent
	set fso = CREATEOBJECT("Scripting.FileSystemObject")
	
	set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation").Value)

	counter = fold.files.count

	'So long as there is more than 1 file carry on

	if  counter >= 1  then

	for each fil in fold.Files
		DTSGlobalVariables("gv_FileFullName").Value = fil.path
		ShouldILoop = CBool(True)
	Next

	else
		ShouldILoop = CBool(False)
	End if

End Function

DTSTask_DTSDataPumpTask_1 (Transform Data Task: undefined)

SourceDestination
Connection Text File (Source)SQLServerDestination
Object F:\Files\File1.txt[Pubs].[dbo].[dtsloop]
SQL Statement

Transformations

Transformation name Source Destination Transform function
DTSTransformation__1
Col001
Col001
DTS.DataPumpTransformCopy
DTSTransformation__2
Col002
Col002
DTS.DataPumpTransformCopy
DTSTransformation__3
Col003
Col003
DTS.DataPumpTransformCopy

DTSTask_DTSActiveScriptTask_4 (Loop Around)

Description Loop Around
Function name Main
Script language VBScript
ActiveX script
' 246 (Loop Around)
Option Explicit

Function Main()

	dim pkg
	dim stpbegin
	dim fso
	dim fil
	dim fold

	set pkg = DTSGlobalVariables.Parent
	set stpbegin = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
	
	set fso = CREATEOBJECT("Scripting.FileSystemObject")
	
	'The trick to looping in DTS is to set the step at the start of the loop to an execution status of waiting

	stpbegin.ExecutionStatus = DTSStepExecStat_Waiting

	'This is how we do our archiving.  We use the FileSystemObject to move
	'the file to another directory
	'I extend this even further in my packages and zip the files up as well.
	'I do this using the command line zipping tool from PKWare
	
	fso.MoveFile  DTSGlobalVariables("gv_FileFullName").Value ,DTSGlobalVariables("gv_ArchiveLocation").Value

	Main = DTSTaskExecResult_Success
End Function

DTSTask_DTSActiveScriptTask_5 (Finished)

Description Finished
Function name Main
Script language VBScript
ActiveX script
' 246 (Finished)
Option Explicit

Function Main()

	MSGBOX "Package has Completed."

	Main = DTSTaskExecResult_Success
End Function

DTSTask_DTSExecutePackageTask_1 (Execute MultiplePath)

Description Execute MultiplePath
Package name MultiplePathOR
Package password
Server name SERVER1
Server user name sa
Server password sa
Use trusted connection false
File name
Use repository false
Repository database name

DTSTask_DTSExecutePackageTask_2 (Excute SkipPackage)

Description Excute SkipPackage
Package name SkipTask
Package password
Server name SERVER1
Server user name sa
Server password sa
Use trusted connection false
File name
Use repository false
Repository database name

(go to package (Loop Import and Archive) index)

Steps (Loop Import and Archive)

Step summary

Step name and descriptionTask nameOn completion On success On failure
DTSStep_DTSExecuteSQLTask_1
Define Table
DTSTask_DTSExecuteSQLTask_1DTSStep_DTSActiveScriptTask_1
DTSStep_DTSActiveScriptTask_1
DefineTheGVs
DTSTask_DTSActiveScriptTask_1DTSStep_DTSActiveScriptTask_2
DTSStep_DTSActiveScriptTask_3
DTSStep_DTSActiveScriptTask_2
Bad Directories
DTSTask_DTSActiveScriptTask_2
DTSStep_DTSActiveScriptTask_3
Begin Loop
DTSTask_DTSActiveScriptTask_3DTSStep_DTSDataPumpTask_1
DTSStep_DTSActiveScriptTask_5
DTSStep_DTSDataPumpTask_1
Transform Data Task: undefined
DTSTask_DTSDataPumpTask_1DTSStep_DTSActiveScriptTask_4
DTSStep_DTSActiveScriptTask_4
Loop Around
DTSTask_DTSActiveScriptTask_4
DTSStep_DTSActiveScriptTask_5
Finished
DTSTask_DTSActiveScriptTask_5
DTSStep_DTSExecutePackageTask_1
Execute MultiplePath
DTSTask_DTSExecutePackageTask_1
DTSStep_DTSExecutePackageTask_2
Excute SkipPackage
DTSTask_DTSExecutePackageTask_2

Step properties

DTSStep_DTSExecuteSQLTask_1 (Define Table)

Property Value
Task nameDTSTask_DTSExecuteSQLTask_1
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success DTSStep_DTSActiveScriptTask_1
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSActiveScriptTask_1 (DefineTheGVs)

Property Value
Task nameDTSTask_DTSActiveScriptTask_1
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success DTSStep_DTSActiveScriptTask_2
DTSStep_DTSActiveScriptTask_3
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSActiveScriptTask_2 (Bad Directories)

Property Value
Task nameDTSTask_DTSActiveScriptTask_2
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSActiveScriptTask_3 (Begin Loop)

Property Value
Task nameDTSTask_DTSActiveScriptTask_3
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Steptrue
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success DTSStep_DTSDataPumpTask_1
DTSStep_DTSActiveScriptTask_5
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSDataPumpTask_1 (Transform Data Task: undefined)

Property Value
Task nameDTSTask_DTSDataPumpTask_1
Add global variablestrue
Close connectiontrue
Commit successfalse
Disable Steptrue
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success DTSStep_DTSActiveScriptTask_4
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSActiveScriptTask_4 (Loop Around)

Property Value
Task nameDTSTask_DTSActiveScriptTask_4
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSActiveScriptTask_5 (Finished)

Property Value
Task nameDTSTask_DTSActiveScriptTask_5
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSExecutePackageTask_1 (Execute MultiplePath)

Property Value
Task nameDTSTask_DTSExecutePackageTask_1
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success
On failure
Script languageVBScript
Function Name
ActiveX Script

Step properties

DTSStep_DTSExecutePackageTask_2 (Excute SkipPackage)

Property Value
Task nameDTSTask_DTSExecutePackageTask_2
Add global variablestrue
Close connectionfalse
Commit successfalse
Disable Stepfalse
Execute in main threadfalse
Is package DSO rowsetfalse
Join transaction if presentfalse
Relative priorityDTSStepRelativePriority_Normal
Roll back failurefalse
On completion
On success
On failure
Script languageVBScript
Function Name
ActiveX Script

(go to package (Loop Import and Archive) index)

Global variables (Loop Import and Archive)

Variable name Value
gv_FileLocationf:\Files\
gv_ArchiveLocationf:\Files\Archive\
gv_FileFullNameF:\Files\Copy (10) of Copy of Copy of Copy of Copy of Copy of File1.txt
gv_FileCheckErrors Source File directory Not Found Archive File directory Not Found