简体   繁体   中英

SSIS Excel connection string not updating with enumerated file when run inside a foreach loop container via a c# script task

Issue:

My excel connection manager filepath is not being updated by the updated variable being passed in via a Foreach file enumerator.

Functional Requirements:

I have a set of excel files inside a directory that I need to iterate through and import into a SQL Server database.

The first restriction with these files is that one of the columns has up to 3000 characters in each of its cells (blowing out the standard 255 char max).

The second restriction is that I've got a restriction here where I can't take the normal path and update the registry to sample more rows (whereby I would normally create a primer file with the first couple of rows of that column having 3000 chars).

Solution Outline:

Prototype: To counter the >255 char cells and prohibition of editing the registry I elected to use a Script Task which leverages an Excel Connection. Reference:
https://egilhansen.com/2015/07/28/ssis-solution-excel-data-source-text-truncation-column-more-than-255-characters/

I have a single DataFlow task importing one file using this script working, so the script is sound.

FYI, the dataflow task has only 3 dataflow items in it: 1) Script task to ingest the contents of the excel file 2) A derived column that adds in the enumerated filstring 3) an ole db that loads these into a database

All Files in a Folder Solution:

I then set up a Foreach Loop container and copied the script task into it.

I configured the properties of the Excel connection's Expression to have a property of filepath and mapped the filename variable to it that the foreach file enumerator is mapped to.

Lastly, I set the Delayvalidation on the control of flow task, the excel connection and the Excel connection manager's properties.

sidenote: In the Foreach File enumerator the derived column is actually adding in the enumerated filenames correctly --> its just the excel connection string that isn't also updating.

Closing comments: I messed around changing the excel file expression to be a ConnetionString and added in another variable and script task to change it inside of the foreach loop (leveraging the enumerated file variable), but the ConnetionString variable isn't updating...... I'm now wondering if I need to nest a foreach loop container inside the existing foreach loop to update the excel connection strings variable before then proceeding to the main script

I do not have the reputation yet to comment and I apologize. I see in your last comment you stated that the connectionstring isn't updating. That is an issue I have experienced with SSIS before where it won't assign the value of a variable inside of the component. Meaning if your inside the loop it won't assign the value until it completes the loop. This applies to Data Flows as well. The way around it is to have that value set prior like what you suggested with the nested loop. If you don't mind we can use this as the comment essentially to help you with your resolution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM