SSIS package configurations - ssis

how to load multiple Excel files using SSIS. I have had Packages in the past where I was looping through multiple Text files in a folder and loading them into SQL server tables.

Create a variable named FileName, set the scope to ImportMultipleExcelFiles, Data type is String.
Add a Foreach Loop Container in the Control Flow Task.
Edit the Foreach Loop Container, in the Collection section change the Enumerator value to Foreach File Enumerator
You need to change the Enumerator configuration as shown below :
Folder: Provide a complete folder path location where all our Excel
source files are stored.
Files: you need to read the Excel files from our source folder, so
enter *.xls in the Files section, this will make sure our SSIS
package will read all available .xls files from the source folder.
Here * indicates that the Excel file name can be anything, but file
extension will be .xls. If we need to read data from a specific Excel
file name then we have to configure it accordingly.
Retrieve File Name: select the Fully Qualified radio button.
Then, create variable mappings for the Foreach Loop container, select the "User::FileName" variable and set the Index value to 0 in the Variable Mappings section.
Add a Data Flow Task inside the Foreach Loop Container.
Right click on the recently added Data Flow task and click on Properties and mark the DelayValidation property to True.
Add an Excel Source in the Data Flow Task and create a new connection to any of the Excel source files.
You have to make the Excel connection dynamic so that it can connect to each Excel file in the source folder. To make the Excel source connection dynamic, right click on Excel Source Connection and then click on Properties.
Expand the Expression Properties, then select the Connection String property and then click on the expression icon, in the expression window :
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+#[User::FileName]+";Extended Properties=\"Excel 8.0;HDR=YES\";"
Finally, execute the SSIS package and see the result.

Related

How does value in variable reach Flat File Connection Manager and/or Flat File Source?

In my Data Flow Task object, I have a Flat File Source object and an ADO NET Destination object. The Flat file connection manager in Flat File Source object points to file C:\BIDS\Ssis\TextFiles\Summary_090115.txt. That's the file that will be read when the package is run.
Since the filename will not be the same, I've added a Foreach Loop Container that will retrieve the filename to variable FilePath. So now, in Control Flow tab, FilePath should have the name of the file to read.
My question: how does the value in variable FilePath reach the Flat File Connection Manager used by Flat File Source object in Data Flow tab?
Thanks.
You can set the ConnectionString expression in the Properties menu for the FlatFile Connection manager
This is a link from Microsoft
This is an article on how to accomplish your task
First have a variable build a ConnectionString
RightClick on FlatFile Connection Manager and select Properties (alternatively select the connection manager and press F4)
Click on the ... next to Expressions
Select the Connection String Property and set it to the Variable that builds the connection string dynamically

SSIS: How to change metadata on flat file connection manager

I am working in BIDS. I have an SSIS package that loops over all files in a given directory and imports all of them to a table. So, my control flow has a Foreach Loop Container with a Data Flow Task inside of it. The Data Flow Task goes straight from a Flat File Source to an OLE DB Destination. Because the directory can change, I have made the Foreach Directory dynamic (i.e., I gave it a package variable, which I can change when the directory changes). The Files field has something like stuff*.pip, such that all files in the directory that match this pattern get imported. The Variable Mappings tab has a file name variable, which is the same variable used in the Expressions of the flat file connection manager.
When I originally set up the flat file connection manager, I had to point it to an already existing file to pick up the file's metadata. I then changed the file connection manager to dynamic (i.e., I added a file name variable in the Expressions property) such that the Foreach Loop Container will pick up all files (that match the pattern).
Since then, the metadata on the file has changed. So, when I open the solution file, it throws a warning on the Flat File Source in the Data Flow Task. To resolve this, I have to temporarily change the flat file connection back to a hard-coded path such that I can change the metadata on the new file. I then make it dynamic again (i.e., use the file name variable in the Expressions, which overrides the hard-coded file path). (Finally, I double-click on the Flat File Source in the Data Flow Task to automatically update the metadata in the Flat File Source.)
Is this the correct way to update the metadata on a flat file? It seems a bit clunky to me.
You can prevent this error from occurring by editing the properties on the Flat File Manager and setting ValidateExternalMetaData=False.
You may also need to set DelayValidation=True on the Data Flow Task that contains the Flat File Manager.
This will prevent the warning - but if the file's metadata changes for some reason (columns change, data types change) and you do not remember to update the metadata then you will get a runtime error.

SSIS For Each Loop crashes the flat file connection

I created a simple SSIS package to import a flat file (.txt) into a database table. Tested that and it works perfectly. Since I have several files to import, I added a foreach loop to go through all the files, added the variables as recommended in several examples found on the net but now my flat file connection manager returns an error of "A valid file name must be selected." and the package will not run. I have so far been unsuccessful in finding the solution for this issue and would appreciate any suggestions by the SSIS gurus of this forum. Many thanks in advance!
Here is what I have in the way of variables:
SourceFileFolder which is the path to the folder that contains the files
FileName a string containing one of the names of the files I am seeking to import
SourceFilePath which is an expression driven variable that incorporates the previous two variables concatenated together. I can click "Evaluate Expression" and copy and paste it into windows explorer and open the file
ArchivePath which is an expression driven variable that creates the path to archive the file to once it is processed.
As the message says this is related to your connection manager not gathering the connection string. This can be handled using the following:
First of all clear the expression on the SourceFilePath variable.
With your Foreach Loop Container, set it up as follows:
This will use your variable SourceFileFolder as the Folder, you could also just hardcode the folder name C:\ for instance. Also make sure your folder is qualified correctly, I.E. make sure it finishes with a slash C: won't work but C:\ will work.
Next you need to map the fully qualified name to your other variable SourceFilePath
This should now store the full name of the file the loop has found into the SourceFilePath variable. For Instance C:\File.txt, you can now use this as a connection string expression on your file connection manager.
Under the properties of the connection manager make sure the expression is set to ConnectionString and then use the SourceFileName variable.
ALSO MAKE SURE DELAY VALIDATION IS SET TO TRUE
This hopefully should mean you can loop through the files.

SSIS copy files task

I have a list of file paths in a table. I need to read these file paths copy these files to a drive which is on present on another server without changing the directory structure. Is this possible ?
You could implement this in SSIS in the following way:
Create a Data Flow Task. In the Data Flow Task, add a Data source component to fetch the filenames from the table. Add a Recordset Destination component and connect the two
Create a For Each container. Connect to the Data Flow Task created in step 1. Change the enumerator type to ADO enumerator
In the For Each task, add a Script Task that takes the file name and uses System.IO.File::Copy method to copy the file to its destination.

importing thousands of files in a flat file manager SSIS data flow task sql server 2008

I am trying to import multiple tab delimited files into a sql server table using a SSIS package. I set the flat file source and created a flat file connection manager but I was told I will need to create multiple flat file sources for this. This cannot be true right?
Is there not someway I can use a loop and the source folder directory location?
So long as the files are all the same structure, you'd use a for-each loop, of type file. Point it at the folder with the files in, and assign a variable to the file+path. Then use that variable as an expression on the flat file connection manager.
Here is a link that shows how to do this: http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx
I like the layout and the graphical indicators used on that page.