Solved

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

Posted on 2011-03-21
4
514 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now