.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

SSIS 2005 - Foreach loop container - Stopping the loop after processing X number of file?

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :Sql Server
I need to stop the Foreach loop container from processing more files in the folder than desired. Scenario:  If I only want 1 files processed, i need to stop the loop after it finds 1 file.  No matter what the contraints or tests or variables I set, the loop processes all the files in the folder.  This is bad because I need the value of the 1st mapped variable and not the last one it finds. I have tried counting records and setting variables used in the contraints but to no avail  Nothing seems to stop the loop. Please advise

View Complete Post

More Related Resource Links

Using Foreach loop Container in SSIS 2005 package and scheduling the package using SQL job on 64-bit

I've an SSIS package 2005 which uses a for each loop container, this package runs fine when I run it on the local machine . My server is 64 bit SQL 2005 and I 've successfully deployed my package on the server both to the File system and SQL server. I've also set Run64bitruntime to false in my pacakge. Now I need schedule the package using SQL job. Since Microsoft Jet Provider 4.0 is not available for 64 bit, I had to write script to schedule the package. Here is my script. declare   @ssisstr varchar(8000) declare @returncode int set   @ssisstr = 'dtexec /sq Package1 /DE 123' EXEC   @returncode = xp_cmdshell @ssisstr select   @returncode I'm getting the following error when I execute the job. Could not load package "Package1" because of error 0xC0010014. Description: One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors. I'm getting the same error if I run this from commandline. Any help would be really appreciated. Thanks in advance. PARC

Stopping a SSIS Foreach loop at a certain time.


I have a SSIS package that loops through ANSI 835 files, parses them, and posts the data to the appropriate database.  The issue I have is that sometimes this job can take some serious time and I need it over with at 6am (any remaining files can just wait until the next day).  It is unacceptable to use the SQL Agent to stop the package after 6am because the package may be in the middle of parsing a file and may only post partial data that our users would have to find and take time to clean up. 

Is there a way to include a script task in my Foreach loop such that when it tries to process the next file the Script Task checks the time and if the time is after, say, 6am it stops the loop and reports success?

I added a Script Task to our current package as a visual aid.  See screen shot in below link:



"If you have to ask about various operating system limits, you're probably doing something wrong." -Raymond Chen

Foreach Loop Container & File System Task to copy files from target server to source server


A one-off shot at using, SSIS, I appear to be missing something. 

From what I have read here, the Foreach Loop Container in which a File System Task has been placed is how one copies files contained in a source server folder to a folder on a target server.  I have defined Source and Destination pkg variables using UNC \\servername\aharedfolder and a FileName variable that is empty.  My impression is that this is suppose to iterate through and copies all files in the source folder to the target.  I only get the first file copied.

In the FLC Collection section  I am using the Foreach File Enumerator under which I have the Folder as \\servername\sharedfolder and files as *.* .  I am not using Expressions.  The Variables Mapping reference my FileName variable.

In the FST, I both path variables set to True and reference the destination and source variables described above.  Operation is Copy File.

I appears that I need to pass a list of the source folder file names to the FileName variable, rather than some built-in logic grabbing a files in the source folder.  Is a passed filename list what I am missing?

ForEach Loop Container Configuration Question

So here is my question/situation. I have a table that contains a list of all of our servers/instances for my organization. I have a script that I'd like to execute against all of the servers in that list and I was thinking that I should be able to use this container to pull the name/instance from the table, execute the script, store the results in a local table. However, I'm not quite sure on how to attack this meaning not sure which configuration that I would need to use to get me going down the right direction. I've looked around and found alot of documentation on how to enumerate multiple files and folders, but nothing really for what I'm trying to do. Any help or direction would be greatly appreciated.Big Ern

How to go to next iteration of ForEach Loop container on task failure

I'm using a ForEach Loop container to iterate through a set of files and import/validate the data.  Within each loop, the first thing that happens is that I fill a variable from a table and then use a script task to make sure that the rest of the package should be run for this particular file.  If it should continue, I set Dts.TaskResult = Dts.Results.Success, and if it shouldn't, I set it to Dts.Results.Failure.  My question is, how do I get it to exit the current iteration of the loop and continue to the next iteration?  The way it is now, the package just stops completely.  I set the FailPackageOnFailure property to False for the script task, but that doesn't make a difference.  I also tried pointing a failure precedence contstraint bacl to the loop container, but that's not allowed.  How can I make it just continue in the loop?   Thanks.

Foreach Loop Container.ForEachEnumerator.Properties[FileSpec] Exception -This occurs when an attempt

I run into the following 2 exceptions when I execute a package on SQL Server 2005 64 bit machine. The package fails when SQL Server version is 9.0.3310 which is a production box. I have tested it on 3 others development boxes with SQL version 9.0.1399, 9.0.3315 & 9.0.4053 and the package executes fine. I am unable to make a determination if this issue is related to SQL versions or a bug in the package design. I would like to understand the exception better before I request an SP3 & patches installed to upgrade it to version 9.0.4053 on the production box. I have scheduled jobs to run these packages and we are trying to locate Excel files on a drive using For Each Loop Enumerator. The packages are configured to use configuration files. Please note the destination directory does have the Excel files we are looking for. Source: Well_Test_Package Description: The package path referenced an object that cannot be found: "\Package\Daily Alloc Spread Sheet Foreach Loop Container.ForEachEnumerator.Properties[Directory]". This occurs when an attempt is made to resolve a package path to an object that cannot be found.  End Warning  Warning: 2010-08-31 00:41:13.66     Code: 0x80012017     Source: Well_Test_Package      Description: The package path referenced an object that ca

SSIS FOR each loop to load 1 file after other into database for particaular folder

HI I am using ssis 2008,i have folder in which i have 10 excel file.i wont to load them one after other in data  base I have created a Dataflow task that load one file into database.i have inserted this dataflow task into For each loop and in For each loop i have give that folder path and *.XLSX  and in variable mapping i have created one variable  which i have passed in Database destination connecion string (properties->expression) but still i get error "cannot acquire connection from connection manager" please guide me or provide me with some reference so that i cud load file from folder into database one after other

Could not set a datasource to Schema Rowset Enumerator in Foreach Loop Container



Everytime I want set a datasource (also if I create a new one with an click on the drop down) I got the following error message from the container.


TITLE: For each schema rowset

The new connection, LocalHost.ReportServer, is not an OLE DB connection so it can not be used by the schema rowset enumerator and, therefore, will not be added to the connections list.

But if I generate a OLE DB connection manually it does not appear in the dropdown list of the container. Does anybody know what I have to do in that case?

Thanks, Nils

Foreach Loop Container - Excel



I´ve seen a few posts on this topic but I still can´t get my simple example to work. What I want to do is to loop thru all Excel files in a folder and put some of the data in my db. It works fine without the Foreach loop container. This is what I´ve done. First, I´m working on a Windows Server 2008r2 and against a SQL Server 2008r2. The Excel files are Excel 2007.

1) I created a new Integration Services Project.

2) I added a Data flow task to the Control flow tab.

3) I added two connection managers. One for the Excel file source and one for the destination db.

4) I added an Excel Source and a SQL Server destination and connected them. It works fine, I can preview the columns and the mapping is done correct.

When I run it, the db is populated.

5) This is where it fails. I added a Foreach Loop Container and drag the Data flow task into it. In the collection tab I choose Foreach file enumerator and browse to the folder.

5) Under the variable mapping tab I add a variable called FileName under the scope User and inddex 0.

6) Then I flipped to properties for the Excel Connection manager and enter the expression setting. I added a connection property with this expression "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @[User::FileName] + ";Extended Properties=\"E

foreach loop - delete file task


i have ado enumerator on foreach loop and one of the variable contains the file name. following are the task which get executed in for each loop but i'm getting error on delete file task

1. Run a script to create pdf file from ssrs (using filename and path in ado enumerator). Working great.

2. Send email with attached of above pdf file (working great)

3. Now in 3rd step, i want to delete the file, so used file system task and delete file . i'm getting following error

[File System Task] Error: An error occurred with the following error message: "The process cannot access the file 'p:\information technology\report output to send\eft\0000023744-EF_DEN1_10-29-10_EFT.pdf' because it is being used by another process.".

I'm not sure what is using the file that it is not letting me delete the file.

Any clue?

mark it as answer if it answered your question :)

ForEach Loop reads next file when child task fails


We have a ForEach loop that reads over a list of files in a directory.  We are placing the current file name into a parent variable and passing it into children packages through the Parent Package Variables configuration.  We have attached a Execute Package task for the ForEach loop Failure constraint.  The package is an exception handler that moves the current file (set in the ForEach loop variable mapping) to a failure folder.

The issue is that when the exception handler is called, the file name being passed in is the next file in the directory, not the file currently being processed.  Is this due to read ahead by the ForEach loop?  I pass this variable exactly the same way to child packages within the ForEach loop and it works fine.  It is just when I pass the variable to the constraint path from the ForEach loop that changes the value of the variable.  Is this because the exception handler sits outside of the loop container?

Thanks for your help.


how to get current loop order number in "for each" ?

For Each item As pages.tbl1Row In pagesdim x as integerx = ?????response.write("current loop is :" & x )               Nextwhat code i need to replace with "?????" to get current loop order?

Error on 23rd Loop of Foreach

Hi, I have a MAster Package callling 8 Dimension Package and 5 fact table packages. Fact table Packages are in for eachloop. They have to loop 24 times during FirstRun Each fact table load more than 500000 rows in every loop, and out of 5, two package loads more than million rows in every loop. I got the following error message when the package was looping for the 23rd time. One of the five Fact table package failed with following error DTS primeoutput failed returned error code 0xC02020C4 SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Staging Table "(1) returned error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. After when I ran package explicitly, it ran well Please help on what to be done to avoid this error and what does this error mean?. I am Using SQL Server 2008, i5 Processor, 3.42GB RAm, DefaultBufferMaxRows = 10000 and Default BufferSize 10MB, EngineTHread=10 Thanks, Anuja

Loading Decimal Number From Excel into SQL Server 2005 using SSIS Package

If you have an excel spreadsheet that displays a number .02 (because it is formated) but internally it is stored as .2654329 and you want to load .2654329 how can you do that in the SSIS package?  When we load the spreadsheet it is loading .02.  Is there some kind of option in the SSIS package to tell the package to load the internal number?lcerni

Read Binary Data which is nothing but a Zip file and unzip through SSIS 2005 SP2

Hi ALL, I need some help in developing a task. I have a source database which is Oracle and it has a ZIP file stored inside the database in Binary format. When I move this data into the sql server 2005 database I get the data as binary data. Now the task begins with SSIS, I need to read the binary data which gives us a zip file and then unzip this zip file and read the XML data which is present inside the Zip file. I beleive some one might have already developed this task can you share the solution with us. Note: As this has to be moved into production I dont have permission to use third party tools like Cozy roc or install winrar.exe and simpy calling this exe from the execute process task in SSIS.  Raju

C# Allowing user to select variables to use in a foreach loop

Hi guys, First project, first post. My app builds webpages and personalises the content by running a foreach loop through rows in a dataset. My original web page build was hardcoded and works fine. I want to take this one stage further and allow users to paste their own html into a text box and use button controls to insert values from the dataset arrays.  Doing this however leads to the app writing the string verbatim. Some examples at this point might help:  Original code here System.IO.StreamWriter objWriter; objWriter = new System.IO.StreamWriter(webpage);                     objWriter.WriteLine("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>"); objWriter.WriteLine("<head>"); objWriter.WriteLine("<title>" + row.ItemArray.GetValue(0).ToString() + "'s very own webpage" + "</title>";); objWriter.WriteLine("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"); objWriter.WriteLine(""); objWriter.WriteLine("</head>"); objWriter.WriteLine("<body>"); objWriter.WriteLine("<h1>Well hello there " + row.ItemArray.GetValue(5).ToStri

SSIS For Each loop with data flow hangs on DTC (SID -2) when inside transaction

The short story: I have a data flow inside a For Each container that is inside a sequence container.  A transaction is established at the sequence container, with Isolation Level Serializable.  The For Each container is limited to execute only 4 iterations.  The data flow iterates once fine, but the second iteration hangs.  The Activity Monitor shows the process is waiting on a another process with a SID of -2.  From other research in the past, I have found that this is an internal process dedicated to DTC (Distributed Transaction Coordinator). Environment: Microsoft SQL Server 2005 (SP3) on Windows 2008 R2 Standard.  I'm using SQL Server BIDS 2005 for building these packages.  I also have SQL Server 2008 installed and the databases are installed there. The details: The data flow merges data from the same table in two databases, source and target, using a Merge Join component.  It then performs a few transformations and lookups from other tables in the target DB to get IDs.  Then it inserts new records into the target DB or updates existing records in the target DB.  The two source tables are using OLE DB Source components with customized queries.  The insert target component is an OLE DB Destination and the update target component is an OLE DB Command.  In this particular scenario,
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend