Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-21
4
Medium Priority
?
525 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore 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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview

971 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