Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if file is empty (SSIS)

I am trying to develop a package in SSIS 2005 and part of my process is to check if a file on the network is empty or not. If it is not empty, I need to pass a status of successful, otherwise, I need to pass a status of unsuccessful. I think I need a script task, but am not sure how to go about it. Any help is appreciated.

like image 279
DoubleJ92 Avatar asked Dec 13 '22 15:12

DoubleJ92


2 Answers

Create a connection to the flat file in the Connection Managers panel. Under the Control flow tab, add a Data Flow Task. enter image description here

Double click the Data flow task and add a Flat File Source and Row Count item. enter image description here

In the Row Count properties, create a RowCount variable. enter image description here

In the Control Flow tab, create control flow connections based on the result of the @RowCount. enter image description here

like image 188
jim31415 Avatar answered Dec 28 '22 09:12

jim31415


There are two ways to do it:

If file empty means size = 0 you can create a Script Task to do the check: http://msdn.microsoft.com/en-us/library/ms345166.aspx

If My.Computer.FileSystem.FileExists("c:\myfile.txt") Then

  Dim myFileInfo As System.IO.FileInfo
  myFileInfo = My.Computer.FileSystem.GetFileInfo("c:\myfile.txt")

  If myFileInfo.Length = 0 Then
    Dts.Variables["Status"].Value = 0
  End If
End If

Otherwise, if file empty means no rows (flat file) you can use the a Row Count transformation after you reads the file. You can set a variable from the Row Count using the 'VariableName' property in Row Count editor and use it as a status.

like image 33
pcofre Avatar answered Dec 28 '22 08:12

pcofre