Solved

SSIS Script Task: Failing at the end of a Loop and not sure why

Posted on 2011-03-21
4
517 Views
Last Modified: 2012-05-11
I finally found a way to loop through a directory to get the most current file from a directory. Now, after it goes through the loop and moves to the End If part of the statment, it ends with failure. Here is a copy...please help...am I missing something? (please note the MsgBox are only there for debugging this process)
-------------------------------------------------------------------------------------
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO ' ADDED

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
      Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

      Enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
      End Enum
    Public Sub Main()
        Try
            'GET SSIS Variables
            Dim strFolder As String = "\\HSFTPSRV\FTPDATA\Patriot\"
            Dim strUpdatedFolder As String = "\\HSNAS01\FileServer\Clients_Data\CLIENTS\PATRIOT\MED\PreCerts\"
            Dim files() As String = System.IO.Directory.GetFiles(strFolder, "*.*")
            Dim FC As Integer = 0

            Dim strOriginalFile As String = files.GetValue(FC).ToString   'returns the value of first file name list
            Dim dt As DateTime = File.GetCreationTime(strOriginalFile)

            Dim PreCertFile As String
            Dim NewFileName As String
            Dim PreRawFile As String

            MsgBox(strOriginalFile)
            MsgBox(dt)

            If Not (DateTime.Now.Subtract(dt).TotalDays < 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                For Each strOriginalFile In strFolder
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                    MsgBox(strOriginalFile)
                    MsgBox(dt)
                Next
            End If

            MsgBox(strOriginalFile)

            PreCertFile = strOriginalFile
            NewFileName = strOriginalFile = Replace(strOriginalFile, ".TXT", "") + ".TXT"
            PreRawFile = Replace(strOriginalFile, strFolder, strUpdatedFolder)

            MsgBox(strOriginalFile)
            MsgBox(PreCertFile)
            MsgBox(NewFileName)
            MsgBox(PreRawFile)

            'Create the file processed in the new directory
            'File.Create(PreRawFile)

            'GENERATE an Information Event
            Dts.TaskResult = ScriptResults.Success
            'Dts.Events.FireInformation(10000, "Script", "Texfile updated.", "", 0, False)

        Catch ex As Exception
            Dts.TaskResult = ScriptResults.Failure
            Dts.Events.FireError(20000, "Script", "Error description.", "", 0)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class-------------------------------------------------------------------------------------
0
Comment
Question by:RicS77
  • 3
4 Comments
 
LVL 25

Expert Comment

by:TempDBA
ID: 35182721
Decrease the loop by 1 and handle the last one some other way.
0
 

Author Comment

by:RicS77
ID: 35183903
Not sure I follow...
What about this?

   If Not (DateTime.Now.Subtract(dt).TotalDays < 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                For Each strOriginalFile In strFolder
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                Next
            Else
                PreCertFile = strOriginalFile
                NewFileName = strOriginalFile = Replace(strOriginalFile, ".TXT", "") + ".TXT"
                PreRawFile = Replace(strOriginalFile, strFolder, strUpdatedFolder)
            End If
0
 

Accepted Solution

by:
RicS77 earned 0 total points
ID: 35184206
Figured it out using this instead.

       Dim BGN As Integer = 0
            Do While BGN = 0
                If (DateTime.Now.Subtract(dt).TotalDays > 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                    BGN = 0
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                Else : BGN = 1
                End If
            Loop
0
 

Author Closing Comment

by:RicS77
ID: 35221272
Found the solution to the problem before receiving an approved solution from EE.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question