Foreach Container to loop through Multiple Excel File to load - sql-server

I have had Packages in the past where I was looping through multiple Text files in a folder and loading into sql server tables.
Now I am asked to create a package which will loop through Multiple Excel Files in a folder and load them into sql server table.
I went through the following steps to create this package assuming it shouldn't be much different from what I have in other packages where it loops through multiple Flat file.
Added an Execute Sql Task, Truncating my staging table, A simple Truncate table statement.
Added a Foreach Loop Container. Selected Foreach File Enumerator and created a variable called File_Path with data type string.
Added a Data Flow Task.
Added an Excel Data Source. and configured the Excel Connection manager By selecting any one 'Excel' File in the destination folder. (At this point is configured correctly as it is not showing any red cross or warring messages.)
Then I selected the Excel File Connection Manager and in Properties windows Under Expressions, Selected Connection String property and Used the User Variable #User::File_Path.
At this point the Excel Data source is showing a Red Cross as it needs further configuration.
I have tried a few things Like changing the Data Access Mode from Table name to Table Name or View Name Variable, And passing variable #User::File_Path but it gives me the following error.
Can someone please have a look and advice where I am going wrong and how I can fix this? Any Advice or a pointer in the right direction is much appreciated.
Thank you.

You shouldn't use an expression on the ConnectionString property, but on the ExcelFilePath property.

Related

How to set file source via Parameter in SSIS?

I have multiple packages for each location site and each site contains 5 other sub sites for which data has to be populated every month. Hence I have approx 20 excel files as a source data for which the excel file acts as a source and I need to create an excel destination. Because of so many excel file as a source I have multiple Excel connection Managers (Source + Destination) across my various packages.
The source file name and the location will change everytime and so I was thinking to automate the file path via parameter. I follow the steps mentioned in the article: https://blogs.msdn.microsoft.com/sqlgardner/2015/06/18/ssis-tip-using-a-file-path-parameter-for-multiple-flat-files/
I followed every step but I got the error when I open the excel file (source). Below is the error snapshot:
Can someone guide me what exactly I am doing wrong here?
Looks like you're using an expression on the excel connection manager "ConnectionString"
property. When that property is changed to just a file path that isn't a valid connection string for that type of connection.
With excel file connections it's a little different and you'll want to use the ExcelFilePath property, which in turn is used by the connection manager when building out the connection string.
With Flat File Connections, yes you would use the ConnectionString property, Excel Connections, slightly different, use the ExcelFilePath property.

SSIS - #na in ms sql while importing excel data

I have build a SSIS package where all .xlsb files are pulled from a folder and updated to a temp file. I had built the package with the existing excel files I had, it worked fine and now I have received a new data set in xlsb only but I see few columns getting update as #NA. Also I get error
Also with the new data I got error saying
VS_NEEDSNEWMETADATA
so I turned the data validation to false
The VS_NEEDSNEWMETADATA error is probably because you changed something in your schema. just double click on your inputs/outputs, click OK and it should resolve itself.
Have you checked what columns/fields are getting updates as #NA? Most likely it are fields that are empty in the xlsb and could be replaced in your SSIS package with null by using a derived column.
If you are using Excel Connection manager, try below things:
In source task, test with both the options (true/false) of 'Validate external Metadata'
If your excel column contains combined values of characters, numbers and alphanumeric, add IMEX=1 to the extended properties of excel connection manager.
https://www.youtube.com/watch?v=s3d-XIYuB7k

SSIS Flat File Source Text Qualifier being ignored

I am using SSIS to insert data from flat file to database.
I have created Data Flow Task for that. I am using Flat File as Source and ADO NET Destination to insert data.
Below is how my setting looks like for Flat File Source.
Below is how my "Columns" tab look like
THIS WORKS FINE WHEN I RUN THAT USING BIDS AND DATA IS INSERTED PROPERLY INTO DATABASE. IT EVEN WORKS WITH DTEXEC.EXE WHEN RUN LOCALLY.
Now, The problem is with executing the package on the server using dtexec.exe. On the server, data is inserted properly but the text qualifier (double quotes) given is totally ignored while inserting data to database. THE SAME WORKS TOTALLY FINE WHEN RUN LOCALLY. I have attached image below for how its stored in database.
I have checked SQL SERVER version and SSIS version locally and on remote server and both are same.
What can be the problem? Can anyone help?
So I found a solution for this problem. Thanks to LukeBI answer here
Create a string variable called TextQualifier and assign the value " (double quotes)
Select the connection manager, and in the Properties window select 'Expressions'. See below.
Click ..., add the property 'TextQualifier' and assign the variable #[User::TextQualifier]. See below image
Now its working fine. It will even work on 64 bit OS now.
In the flat file source, click "Columns". Make sure that when you preview the data there are no quotes in the preview. Otherwise you may have to look back at your file and make sure that BOTH the text qualifier and delimiter are correct.
If this does not work, then please take a screenshot of the "Columns" screen as well and post it. A screenshot of the actual file layout would help as well. Hope this helps!
Within your flat file connection Manager, within the "Advanced" option, you should be given a view of different parameters for each field. You will see for each field it will have a Name, ColumnDelimiter, a bunch of faded out fields and the DataType and a choice if it is text qualified or not.
In there, you should specify that the column(s) which you wish to be determined as text qualified by setting the TextQualified option to true.

SSIS is overwriting excelfilepath expression with user variable on first pass through for each loop

I have searched everywhere for an answer to this so I am hoping someone out there can help.
I am trying to follow the steps laid out for importing data from multiple excel files in SSIS. I have several excel 2010 files in a directory and am trying to move them into a SQL Server 2008 r2 Database. I have followed all of the directions for doing this with a For Each (File) Loop. I have set the collections information and am using the User::Filename variable to pull back the Fully Qualified filename. The problem I have is that when I check the properties of my excel connection manager-->click on expressions-->modify excelfilepath by setting it to #[User::Filename], SSIS immediately overwrites the property with the new value which is blank (the first time). This then causes my package to fail during execution because there is no filename to go to in the connection.
I have set the delayvalidation property to True on the package, the dataflow and the excel connection and this does not fix the problem. I have also tried to put a fully qualified filename into the User::Filename variable during initialization and this does allow me to process a few files but then gives me a locking error when SSIS tries to re-read the file that I put in during initialization.
I have not found anything like this on the net yet...Hopefully, someone out there has seen this.
I would split this SSIS package into two. The master package would go as deep as the For Each File Loop, but would not include the Excel Connection Manager. The sub-package would open and process each Excel file. It would receive the Filename variable value via Configuration for a Parent Package Variable or similar.
This seems to have the effect of "closing" the excel connection after each file is finished.
I also prefer the OLE DB driver from the Access Database Engine over the native SSIS Excel connection.

Import multiple Excel files into SQL Server 2008 R2 using SSIS Packages?

I have to insert data into two tables from two different excel sheets using SSIS packges.
So, please some one tell me How to import multiple Excel files into SQL Server 2008 R2 using SSIS Packages?
since you have only 2 excel files and only two tables I don't see why use a foreach loop. Just follow this link and do it directly
If you need to insert from both excel files to both databases you can use a multicast component to create a copy of a dataset
Use Foreach Loop Container --> Foreach File Enumerator. Then put your Data Flow in Foreach Loop Container.
Table structure and sheet name have to be equal in every Excel file.
Here is nice tutorial:
http://bi-polar23.blogspot.com/2007/08/loading-multiple-excel-files-with-ssis.html
You can create and use variables to hold Excel file path, then implement the package within a for-each-loop container to loop trough each excel files in the folder. Make sure that the files are having similar data format and same extension.
Create an integration service project in Visual Studio and follow the steps below:
Right Click on canvas and add Variable say "FilePath" and set type
as String
Drag a for-each loop to canvas
Right click on for-each-loop and select "Edit" and add path and file extension and then select the variable from "Variable Mapping" tab as shown:
Add a Data-flow task in to the loop and double click to open it.
Add an Excel source and OLEDB destination (if destination is SQL Server). By right clicking on these controls and choosing "Edit", you can select appropriate folder for Excel and its Data Sheet as well as specify SQL server database credentials in the destination. Connect source and destination using blue arrow. Check and modify mappings between columns, if needed.
Create an expression to read each file to the variable. This can be done by selecting created "ExcelConnectionManager" and select its "Expression" property and expand to set variables to "ExcelFilePath"
And that is it. You are ready to execute the package by coming to Control flow tab and select "Start".
Ref: https://www.encorebusiness.com/blog/import-data-from-multiple-excel-files-sql-ssis/

Resources