When running the following code, I get an error "Microsoft Data Transformation Services (DTS) Package connection ('Text File(Source)')was not found. I do have a text source connection defined in the package. What did I do wrong?
Here is my code
Thanks!
Margaret
Here is my code
Code:
Function Main()
Const DTSSQLStgFlag_UseTrustedConnection = 256
Dim oPKG, oStep
Dim i, bStatus
Dim sFolder
' path must end in \
sFolder = "\\Ttc_datamart\Econz\NotifierCsvFiles\"
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(sFolder)
Set fc = f.Files
For Each f1 in fc
if right(lcase(f1.name),4)= ".csv" then
Set oPKG = CreateObject("DTS.Package")
'oPKG.LoadFromSQLServer "Africa", , ,DTSSQLStgFlag_UseTrustedConnection, , , , "EconUpdate"
oPKG.LoadFromSQLServer "Africa","sa", "xxxx",DTSSQLStgFlag_Default, , , , "EconUpdate"
Set cn = oPKG.Connections("Text File (Source)")
cn.DataSource = sFolder & f1.name
oPKG.Execute
bStatus = true
For Each oStep In oPkg.Steps
If oStep.ExecutionResult =DTSStepExecResult_Failure Then
bStatus = True
End If
Next
oPKG.Uninitialize()
Set oPKG = Nothing
if not bStatus then
MsgBox "An error happened while importing " & sFolder & f1.name & ". The error(s) are logged in " &sFolder & replace(lcase(f1.name),".csv","_error.log")
else
Set oPKG = CreateObject("DTS.Package")
oPKG.LoadFromSQLServer "africa", "sa","xxxx", DTSSQLStgFlag_Default, , , , "Read TRI Text files into econupdate"
Set cn = oPKG.Connections("Text File (Source)")
cn.DataSource = sFolder & f1.name
oPKG.Execute
For Each oStep In oPkg.Steps
If oStep.ExecutionResult =DTSStepExecResult_Failure Then
bStatus = True
End If
Next
if not bStatus then
MsgBox "An unknown error happened while importing " & sFolder & f1.name
end if
oPKG.Uninitialize()
Set oPKG = Nothing
end if
end if
Next
Main = DTSTaskExecResult_Success
End Function
Thanks!
Margaret