Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

SSIS 2012 - load a series of xml files using ForEachLoop Container into a SQL Server table

$
0
0

I have a series of xml files (.xml) along with a common .xsd file;  all the xml files have the same structure - for example: Order, Order Date, Order Details, ....

A Data Flow Task loads the xml data into SQL Server table, and this Data Flow Task is placed into the ForEachLoop Container. Each Output name from an XML file is loaded into a separate SQL Server table (for example OrderDetails xml output is loaded into the OrderDetails SQL Server table). In this way OrderDetails xml output from each xml file is loaded into the (same) OrderDetails SQL Server table.

I am using a ForEachLoop Container to read each .xml file and load into the respective SQL Server table.

I created a user variable called User::Filename and mapped it into the ForEachLoop Container (Variable Mappings) and indexed to 0. The Filename variable is the file path, i.e. name and location of xml file (the first in the series of xml file).

I created 2 other user variables - FolderPath and FileExtension; FolderPath has the value of the location (of the folder where all the xml files are stored), and  FileExtension has the value  *.xml  .

In the ForEachLoop Editor (Collection) , in the Expressions, I have set the following Property expressions:

Directory    -                @[User::FolderPath]

FileSpec     -                @[User::FileExtension]

In the XML Source Editor, I choose the Data access mode as  XML file location, and then provide the XML location and XSD location.

The problem is, even though the package and ForEachLoop Container run without errors, data from the same XML file is loaded into the SQL Server table.

i.e.  say I have 5 different XML files in the folder, the ForEachLoop Container runs 5 times and 5 rows are loaded into the SQL Server table, BUT the same XML file is read and loaded, hence I see 5 identical rows in the SQL Server table. The file that is read and loaded 5 times is the one mentioned in the XML location in the XML Source Editor.

When I change the Data access mode to XML file from variable, and choose Variable name - User::Filename, I see a red cross mark in the XML Source in the Data Flow, and I see the tool tip - the XML file was not found, please verify the file path and try again

I have been having a hard time trying to figure out on how to run XML packages inside a ForEachLoop  Container.  It was pretty easy when I had text files with the same scenario just a day ago.

Any idea will be greatly appreciated.

 






Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>