Quantcast
Channel: Questions in topic: "ssis"
Viewing all articles
Browse latest Browse all 813

SSIS ForEach Loop Container:The parameter is incorrect.

$
0
0
I have a script task that is storing an ID and FileName that is passed back to the package from an excel macro. I'm storing this data in an array and then storing that array to a variable object. This task works fine. I can view that the array is storing thsi data properly and the data is being set to the object variable. (i.e. I can view the data stored when stepping through the code) The next step is a ForEach loop that is set to the variable enumerator type. I'm also pointing to the same object variable. I'm then setting the 2 columns, ID as integer and FileName as String, in the variable mapping. The loop fails with the error: The parameter is incorrect. I can't seem to figure out what i'm doing wrong. From what i've researched this should work. Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Runtime Imports Excel = Microsoft.Office.Interop.Excel Imports System.Collections Structure File Dim fileName As String Dim DeptID As String End Structure _ _ 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() Dim oExcel As New Excel.Application Dim oBook As Excel.Workbook = Nothing Dim oBooks As Excel.Workbooks = Nothing Dim oSheet As Excel.Worksheet = Nothing Dim oSheetSSIS As Excel.Worksheet = Nothing Dim Report As String = Dts.Variables("User::ReportPath").Value.ToString() + "\" + Dts.Variables("User::ReportName").Value.ToString() oBooks = oExcel.Workbooks oExcel.Visible = True oExcel.ScreenUpdating = True oBook = oBooks.Open(Report) oSheet = CType(oBook.Worksheets.Item("Report Parameters"), Excel.Worksheet) oSheetSSIS = CType(oBook.Worksheets.Item("SSIS"), Excel.Worksheet) oExcel.DisplayAlerts = False Dim DateFrom As Date Dim DateThru As Date If Dts.Variables("User::Frequency").Value.ToString() = "7" Then DateFrom = DateAdd("m", -1, DateSerial(Year(Today), Month(Today), 1)) DateThru = DateAdd("m", 0, DateSerial(Year(Today), Month(Today), 0)) ElseIf Dts.Variables("User::Frequency").Value.ToString() = "8" Then DateFrom = DateAdd("m", -4, DateSerial(Year(Today), Month(Today), 1)) DateThru = DateAdd("m", 0, DateSerial(Year(Today), Month(Today), 0)) End If With oSheet .Activate() .Range("C5").Value = Format(DateFrom.ToString(), "Short date") .Range("C6").Value = Format(DateThru.ToString(), "Short date") End With oSheetSSIS.Activate() 'Run the macros. 'oExcel.Run("RefreshAll") ' Change the name of your Macro here. Dim refreshStart As Date, refreshRunTime As Date refreshStart = DateTime.Now Dim alFiles As New ArrayList Dim udtFile As New File For i As Integer = 0 To 1 If CType(oSheetSSIS.Range("B1").Value, Integer) >= 1 Then i = 1 Dim i2 As Integer i2 = 1 Do While i2 <= CType(oSheetSSIS.Range("B5").Value, Integer) oSheetSSIS.Range("B6").Value = i2 If CType(oSheetSSIS.Range("B4").Value, Integer) = 1 Then With udtFile .fileName = CType(oSheetSSIS.Range("B2").Value, String) .DeptID = CType(oSheetSSIS.Range("B3").Value, String) End With alFiles.Add(udtFile) oSheetSSIS.Range("B2").Value = "" oSheetSSIS.Range("B3").Value = "" oSheetSSIS.Range("B4").Value = 0 i2 = i2 + 1 ElseIf refreshStart.AddMinutes(30) < refreshRunTime Then oExcel.Quit() Dts.TaskResult = ScriptResults.Failure Return i = 1 Else i = 0 refreshRunTime = DateTime.Now End If Loop 'oSheetSSIS.Range("B6").Value = 0 'oExcel.Run("SubmitAuto") 'Clean-up: Close the workbook and quit Excel. 'oBook.Save() 'oExcel.Quit() Dts.TaskResult = ScriptResults.Success ElseIf refreshStart.AddMinutes(30) < refreshRunTime Then oExcel.Quit() Dts.TaskResult = ScriptResults.Failure Return 'i = 1 Else i = 0 refreshRunTime = DateTime.Now End If Next Dts.Variables("User::FileSet").Value = alFiles End Sub End Class ![alt text][1] ![alt text][2] [1]: /storage/temp/3984-capture.png [2]: /storage/temp/3985-1.png

Viewing all articles
Browse latest Browse all 813