Using DTS to Detect and Process a File
Introduction
There is nothing better when a new technology lends itself to an old problem. One of the classic
old problems in computing has been to process files that were uploaded to a server. As this problem arose
in a recent situation I was ablt to use DTS to help upload a file into SQL server.
In order to process the file the first step was to be able to detect the arrival of the
file via FTP. Once this had been accomplished the file needed to be loaded into SQL server.
The loading of a flat file to SQL server can be handled by a seperate DTS package but
the more difficult task was detecting, unzipping and starting the processing of the file.
Getting Started
The following is a diagram of what the final DTS package looks like in the DTS Design window. The package
is broken down into four parts. Three of the parts are ActiveX Script Tasks while the fourth launches another DTS Process.
Knowing and experimenting with the various objects one can use in the DTS process quickly expands the tasks that can be
accomplished. This was never as evident as working on this project. DTS had been used previouly to
perform transformations between different database formats and used to combine fields but
the ability to run ActiveX scripts in the middle of the DTS process allowed for some nice
logging and file manipulation.
File Arrival Check
The beginning of the DTS process checks for a file that is created during the DTS process. In creating
a process that can run continuously it is important to check to see if the process had failed
on a previous attempt. In this case if the file that was to be imported into the SQL server
still exists the DTS package failed to properly process on a previous run and the new processing should
not start.
The script to check for the import.txt file follows.
toImport.txt Check Script
|
Marker File
|
Run another DTS Process
Remove File
|
Conclusions
A DTS package is explored and the scripts used to detect a file arrival are
explained. This process is used to load a file into SQL server but the power
of SQL server allows this process to be used for more than just loading data
into SQL server.