Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import multiple files using DTS

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
hello,
~I have created a simple import rountine using DTS, which imports one file.
however, how can I modify this package to import an entire folder of files . ?

thanks for any info, help.
J.
 
Assumptions SQL 2000 on Windows 2000 Server or greater.
I am also going to assume that the files contain similar data, and are going to be inserted into the same table.

What you will need to do is use an ActiveX Task Script to use the FileSystemObject to get a list of files from the directory, then store the first filename in a global variable, then set a Dynamic properties task to start. the Dynamic Properties task then sets the file source of a connection object to point to the new file (based on the global variable). Then the Data Pump task fires. After the data pump task then the active x task fires and is able to loop through the whole thing.

Function Main()
'I am going from memory so some of the File System Object stuff may be off a little.
Dim oPkg
set oPkg = DTSGlobalVariables.Parent
Dim oFSO , oDir, oF
Set oFSO= CreateObject("Scripting.FileSystemObject")
Set oDir = oFSO.GetDirectory("c:\import\")
'Loop of somesort
Set oF = oDir.Files(x)

If oF.Name = DTSGlobalVariables("LastFile").Value Then
Set oF = oDir.Files(x +1)
DTSGlobalVariables("LastFile").Value = oF.Name
Exit loop
End If
if x = oDir.Files.Count Then
oPkg.Steps("Whatever you finish up tasks are").ExecutionStatus _
= DTSStepExecStat_Waiting
Main = DTSTaskExecResult_Success
Exit Function

End If
End loop

oPkg.Steps("Dynamic Properties Task 1").ExecutionStatus _
= DTSStepExecStat_Waiting
Main = DTSTaskExecResult_Success

End Function


DL
MCDBA, MCSD, MCT, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top