October 16, 2008 at 12:48 am
Hi All,
i have a requirement where i need to check if the entire flat file has been FTPed to our machine , before we proceed to the next steps.
first - i check if the flat file is present in the particular directory.
second - i need to check if the EOF has arrived (we will have a "eof record" at the end of flat file to indicate that the entire file has arrived)
third - if eof has arrived , i read the EOF record and get the date from it (this date is taken , to make sure that we dont load the old file today also)
i completed the first and third step using "script task" . But i dont know how to check if EOF has arrived or not.
Here is my current code :
************************************
wait_flag = "Y"
eof_flag = "N"
While (True)
If File.Exists(fileloc) Then
Dts.Variables.Item("User::FILE_EXISTS").Value = True
'System.Windows.Forms.MessageBox.Show("Files exist")
Dts.TaskResult = Dts.Results.Success
Exit While
Else
MsgBox("Waiting for file.......")
System.Threading.Thread.Sleep(180000)
v_Count = v_Count + 1
MsgBox(CStr(v_Count))
End If
End While
While wait_flag = "Y"
Dim oStream1 As New IO.StreamReader(fileloc)
While oStream1.Peek <> -1
strReadLine = oStream1.ReadLine()
If Left(strReadLine, 3) = "EOF" Then
Rcd_Cnt = CInt(Strings.Mid(strReadLine, 106, 10))
filedate = New Date( _
CInt(Strings.Mid(strReadLine, 53, 4)), _
CInt(Strings.Mid(strReadLine, 47, 2)), _
CInt(Strings.Mid(strReadLine, 50, 2)))
eof_flag = "Y"
wait_flag = "N"
Exit While 'leave loop here if EOF found
End If
End While
End While
************************************
In abnormal scenarios , the flat file that will reach us will be partial. Say out of 100K records , only 10K records arrive. At this time , there will not be EOF record in it.
Say, my script task starts at this time.
->since the file exists , it tries to check EOF;
Since this file is partial , it willnot be able to find the EOF record and it will be inside the while loop indefinetely. I dont want this to happen.
I want to end the loop in such scenarios.
Let me know how to resolve this?
Thanks,
Arunvijay
October 16, 2008 at 7:02 am
Please don't cross post.
Post answers to http://www.sqlservercentral.com/Forums/Topic586744-148-1.aspx
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply