Solved

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

Posted on 2011-03-21
4
516 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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

18 Experts available now in Live!

Get 1:1 Help Now