Showing posts with label enumeratorquot. Show all posts
Showing posts with label enumeratorquot. Show all posts

Monday, March 26, 2012

Foreach From Variable using 2 dim array variable

Is there any way to use a 2 dimensional array of strings as the Variable Enumerator for the "Foreach From Variable Enumerator". I am trying to copy a collection of files from folder A to folder B. In a script, I would populate, let us say, an array of (2,10), for 10 files, with one column representing the source file and other column representing the target column task. Then I would like to set this string array variable as the "Variable Enumerator" for the "Foreach From Variable Enumerator" and use file system tasks in the foreach loop to perform the tasks. The problem is that the "Foreach From Variable Enumerator" does not let me choose an index, but passes only one index 0, so, I will only be able to pass just one column. How do I let the foreach enumerator let me choose an index. The other foreach enumerators, foreach item and ADO give me the option to select index. I would like the same functionality in the foreach variable.

Note: I cannot use the "For Each File" enumerator, since the files are to be selected by a script only.
Thanks for the help.

I found a work around by concatenating the variables with a delimiter and then stripping them in a script in the foreach loop. It works ok.|||

When you want more than one variable in enumerator, use a matrix (multi-index) enumerator, of which there are at least two types. The Foreach Xml can be a matrix enumerator, as can the ADO enumerator. In the first case, build an Xml document which represents your data as in

<surveys>

<survey>

<question/><!-- this is index 0 -->

<answer/><!-- this is index 1 -->

.....

For the Foreach ADO matrix enumerator, a very similar option is to build a DataTable object which has multiple columns, load the DataTable with whatever data you want (doesn't need to be from a database), and then use it in the Foreach ADO enumerator, again with multiple indices.

Foreach File Enumerator - is absent in Foreach Loop Component

Hi,

I have no "Foreach File Enumerator" oprtion in the Enumerator Property of the Foreach Loop Component.

I have this enumerator in the c:\Program Files\Microsoft SQL Server\90\DTS\ForEachEnumerators\ folder.

Also I check it in the GAC - it does not here. I try to execute gacutil.exe -iF ForEachFileEnumerator.dll, but it is failed with "Failure adding assembly to the cache: The module was expected to contain an assembly manifest." Seems it is not managed enumerator.

Please help me.

Also information on how to regeister unmanaged enumerators are welcome!

Did you search the forums?

From the thread, http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=608235&SiteID=1, you need to review this KB article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;913817

Also, a user has posted his experience with the same thing: http://mohansmindstorms.spaces.live.com/Blog/cns!69AE1BEA50F1D0E7!203.entrysql

Sunday, February 19, 2012

For Each from Variable Enumerator

Hi ,

Can someone help me in using the "For each from variable enumerator".

The work around that I have made so far is

1) Generating a Enumerated Value of File collection using Script Control

2) A For each Collection container that processes a given set of files.

the above two conditions works for me when executed independently. But I am not able to relate these two, so as to give a enumerator input to the "For each from Variable Enumerator"

any help will be highly appreciated...Thanks

For each from variable enumerator can enumerate over variable that contains .NET collection, e.g. ArrayList. Using it is a bit complex, let's go step by step:

First, create a variable that will contain the collection, let's call it User::Collection, set variable type to Object.

Now populate it in Script Task: create Script Task, specify that it uses this variable for read/write, add a code like this inside Main function:

Dim arr As New ArrayList
arr.Add("D:\Tests\a.txt")
arr.Add("D:\Tests\b.txt")
Dts.Variables("User::Collection").Value = arr

Now add a ForEach loop, specify that it uses Foreach From Variable enumerator, and the variable is User::Collection.

Switch to Variable mapping page of Foreach Loop Editor. We'll need another variable to hold the current value of the enumerator, so click a cell under Variable, select a <New Variable>, create a variable called EnumValue. Leave it associated with Index 0 (our enuration value has only one value).

OK, now add something inside the loop to be executed for each iteration. I choosed File System task, to copy files from the enumerated value to directory c:\tests\destination folder. You can use other tasks, e.g. Data Flow that uses the file in a Flat File Source Adapter.

Open File System task editor. Set operation to CopyFiles. Create source connection (using any file, we'll change it anyway later), destination connection to destination folder. Close the File System task editor.

Now we need to tell the connection manager to use our enumerated value. Select the source connection manager. In Properties panel, select Expressions property and click '...'. Select property ConnectionString, click '...' and drag the EnumValue variable to expression field. The expression should be @.[User::EnumValue].

Finally, we need to set DelayValidation property of File System task to TRUE. The reason is that since the source connection manager gets the value from the variable, we should not validate the task in the beginning of the package.

OK, now run the package! The files added in the script task should get copied to destination folder.