Hi,
Please be patient and bear with me, for I am new to SSIS packages.
I am using SQL Server 2008 R2 to host the SQL Agent job and the SSIS package.
I am using Visual Studio 2008 Professional Edition for designing the SSIS package. It is version 9.0.30729, Version 3.5 SP1.
I am on a Windows 8 machine.
My Foreach Loop Container seems to iterate only once when it should iterate numerous times, and this issue happens BOTH when I execute the SSIS package from within Visual Studio AND when I run a SQL Agent job to execute the SSIS package.
For the solution within Visual Studio, I have False for the property Run64BitRuntime.
In the SSIS pckg in Visual Studio, I have in the Variables pane a number of variables and these following variables pertain to my problem:
Name: objRs Scope: the name of the SSIS package DataType: Object Value: System.Object
Name: txtVendorFamilyNumber Scope: the name of the SSIS package DataType: String Value: 111111
The value "111111" that I entered into the txtVendorFamilyNumber variable in the Variable Pane is NOT a realistic value as there are no vendor family numbers that have the value 111111. I will populate dynamically the real vendor family numbers
from within the SSIS package.
When I imported the SSIS package to SQL Server 2008 R2, via the ellipsis button for the Protection Level I chose the "Rely on server storage and roles for access control" choice.
Concerning the flow of the SSIS package, going down within Visual Studio from the beginning of the flow of the SSIS package, eventually I have an Execute SQL Task. In its General tab, it has "1252" for CodePage property, "Full result set"
for ResultSet property, "OLE DB" for ConnectionType property, "Direct input" for SQL Source Type property, "False" for BypassPrepare property, and the following for the SQLStatement property:
select txtVendorFamilyNumber from tmpVendorFamily where VendorID = (select min(VendorID) from tmpVendorFamily)
In the tmpVendorFamily table on SQL Server 2008 R2, there are 379 rows of results for the SELECT statement above (starting with the values 100110, 100115, 100120, 100130, through the LAST row's value 106370.
In the Parameter Mapping tab of the Execute SQL Task Editor, I have nothing. In the Expressions tab of the Execute SQL Task Editor, I have nothing.
In the Result Set tab of the Execute SQL Task Editor, I have the value 0 for Result Name property and I have the value User::objRs as the value in the Variable Name property.
This Execute SQL Task has a green arrow (Constraint evaluation operation, Success in Value drop down) to the Foreach Loop Container.
In the Foreach Loop Editor, in the Collection tab, I have "Foreach ADO Enumerator" as the value in the Enumerator property. In the drop down for ADO Object Source Variable, I have chosen the User::objRs, and I have the radio button "Rows in
the first table" selected.
In the Foreach Loop Editor, in the Expressions tab, I have nothing.
In the Foreach Loop Editor, in the Variable Mappings tab, I have "User::txtVendorFamilyNumber" for the Variable property and I have the value "0" for the Index property.
So in the Foreach Loop, I first have a Script Task with the ReadOnly variable User::txtVendorFamilyNumber and with the ReadWrite variable User::TESTING_OnlyTesting that I created with a package scope, string datatype, and no default value. This Script Task
has the following code for testing purposes:
Dim strFullVerbiage As String
strFullVerbiage = "The value is: "
Dts.Variables("User::TESTING_OnlyTesting").Value = strFullVerbiage + Dts.Variables("User::txtVendorFamilyNumber").Value.ToString()
Dts.TaskResult = ScriptResults.Success
I have next in the Foreach Loop Container a Send Mail task. In the Expressions tab of the Send Mail Task Editor, I have for the Message Source property the following:
@[User::TESTING_OnlyTesting]
The remaining tasks (including FTP Tasks) in the Foreach Loop Container are disabled for now as I am trying to figure out why the Foreach Loop only iterates the FIRST time, only iterates once.
When I run on SQL Server 2008 R2 the SELECT statement from the Execute SQL Task, I get 379 rows of results. The default value 111111 that I entered into the Variable Pane for the txtVendorFamilyNumber variable does NOT exist in any of these 379 rows of results.
The 1st row of results has for the txtVendorFamilyNumber column the value 100110. Then the subsequent rows of results have the values 100115, 100120, 100130, et cetera, ending with the value 106370 in the last row of results.
I imported the SSIS package into Integration Services on SQL Server 2008 R2. When I imported to Integration Services, in the Import Package editor for the Protection Level I chose the "Rely on server storage and roles for access control" choice
because there are FTP Tasks and we needed to use this "Rely on server storage and roles for access control" choice.
I created a SQL Agent job that executes this SSIS package.
When I run the SQL Agent job, no error happens and I get only ONE email with the value 100110 for the vendor family number in it. I should get 379 emails total, the 2nd email showing 100115, the 3rd email showing 100120, et cetera.
When I was testing while executing the SSIS package from within Visual Studio, I did NOT have the Send Mail task and I only had enabled one Script Task that had the ReadOnly variable User::txtVendorFamilyNumber and the following lines of code:
MsgBox(CType(Dts.Variables("User::txtVendorFamilyNumber").Value, String))
Dts.TaskResult = ScriptResults.Success
Executing the SSIS package with only this Script Task enabled within the Foreach Loop Container, I would get the ONE message box showing 100110 but I would not get any message box for a SECOND ITERATION of the loop.
Since my txtVendorFamilyNumber in the Variables Pane has the default hard-coded value 111111 that does NOT exist in the result set of the Execute SQL Task that feeds the Foreach Loop, and since the first and only email sent shows the value 100110 when I
run the SQL Agent job that runs the SSIS package that is set up to send an email from within the Foreach Loop Container, the FIRST LOOP seems to run correctly and shows correctly the 1st value 100110 in the 379 rows of results that populate the Foreach Loop
Container. Why does the Foreach Loop Container NOT loop more than once?
Could anybody give me any suggestions as to what the problem might be?
I thank you in advance for your consideration of my problem. I have been reading and reading on the Internet to try to find a solution but I have not solved yet my problem with the Foreach loop only iterating once.
Thanks much to you.