How to load multiple files into multiple tables using SSIS for each loop - ssis

Am beginner to SSIS. I have to load multiple files into multiple destinations using For Each loop in SSIS. The problem is for each loop is picking the files names dynamically but while loading into destination table its not changing and pointing to very first table. Which means job is loading the first file correctly but second file its still pointing to first table columns to load second file which causing the error i guess.
I have used below are the variables.
FileName
FolderPath
TargetTable
Please see first table source data in flat file
Second table source data in flat file
Control Flow task
Data Flow Task
Below is the error message :

Related

How to capture SSIS source & destination error records into one file

My goal is to write error records from both source and destination into one file.
Currently, I'm encountering
Warning: The process cannot access the file because it is being used by another process.
PS: As I explore this feature, I can write these error records into two separate files.
Instead of defining two flat file destinations, define just one and union the error outputs to it.

how to handle middle of data failure case in ssis

Hi I have one doubt in ssis
I want load source excel file data into sql server database table.
Source excel file have billions of data(huge data).
whiel loading time halfoffrecords are loaded into destination table after that its failed due some data comes incorrect format .
in this sistuvation how will handle package for loading all data into destination using ssis.
source: excel(Emp information data)
destination : Table : emp
I tried using check point configuration for rerun at the point of failure..
but its not usefully to handled data row level and duplicate data is loading.
and I tried another way truncate data in the destination table.
after that I used redirect row for error handling.buts its not good implementation due to
trunating destination table.
please tell me how many way to achive this task(complete load) in ssis package level.
Load your data from Excel into a staging table, which you truncate before every load.
Make all of the columns of the staging table nvarchar(max) type, so they can handle any format of incoming character data.
Then run a stored procedure that de-dupes, formats and transfers the data to the final destination table.

dynamically adding derived column in SSIS

I have a scenario where my source can be on different versions of our database as a result the in source file I could have different number of columns while my destination have defined number of columns.
now
what we are trying to do is:
load data from source to flat files. move them to central server and
then load that data into central database. but if any column is
missing in flat file i need to add derived column.
what is the best way to do this?? how can i dynamically add derived columns?
You can either do this with BiMLScript as other have suggested in comments, or you can write a script task that reads the file, analyzes the contents, and imports it. Yet another option would be to bulk import the file as is to a staging table (that would have to be dropped and re-created everytime) and write a stored procedure that analyzes the DDL and contents, and imports data to the destination table.

Logging errors in SSIS

I have a ssis project with 3 ssis packages, one is a parent package which calls the other 2 packages based on some condition. In the parent package I have a foreach loop container which will read multiple .csv files from a location and based on the file name one of the two child packages will be executed and the data is uploaded into the tables present in MS SQL Server 2008. Since multiple files are read, if any of the file generates an error in the the child packages, I have to log the details of error (like the filename, error message, row number etc) in a custom database table, delete all the records that got uploaded in the table and read the next file and the package should not stop for the files which are valid and doesn't generate any error when they are read.
Say if a file has 100 rows and there is a problem at row number 50, then we need to log the error details in a table, delete rows 1 to 49 which got uploaded in the database table and the package to start executing the next file.
How can I achieve this in SSIS?
You will have to set TransactionOption=*Required* on your foreach loop container and TransactionOption=*Supported* on the control flow items within it. This will allow for your transactions to be rolled back if any complications happen in your child packages. More information on 'TransactionOption' property can be found # http://msdn.microsoft.com/en-us/library/ms137690.aspx
Custom logging can be performed within the child packages by redirecting the error output of your destination to your preferred error destination. However, this redirection logging only occurs on insertion errors. So if you wish to catch errors that occur anywhere in your child package, you will have to set up an 'OnError' event handler or utilize the built-in error logging for SSIS (SSIS -> Logging..)
I suggest you try the creation of two dataflows in your loop container. The main idea here is to have a set of three tables to better and more easily handle the error situations. In the same flow you do the following:
1st dataflow:
Should read .csv file and load data to a temp table. If the file is processed with errors you simply truncate the temp table. In addition, you should also configure the flat file source output to redirect the errors to an error log table.
2nd dataflow:
On the other hand, in case of processing error-free, you need to transfer the rows from temp into the destination table. So, here, the OLEDB datasource is "temp table" and the OLEDB destination is "final table".
DonĀ“t forget to truncate the temp table in both cases, as the next file will need an empty table.
Let's break this down a bit.
I assume that you have a data flow that processes an individual file at a time. The data flow would read the input file via a source connection, transform it and then load the data into the destination. You would basically need to implement the Error Handler flow in your transformations by choosing "Redirect Row". Details on the Error Flow are available here: https://learn.microsoft.com/en-us/sql/integration-services/data-flow/error-handling-in-data.
If you need to skip an entire file due to a bad format, you will need to implement a Precedence Constraint for failure on the file system task.
My suggestion would be to get a copy of the exam preparation book for exam 70-463 - it has great practice examples on exactly the kind of scenarios that you have run into.
We do something similar with Excel files
We have an ErrorsFound variable which is reset each time a new file is read within the for each loop.
A script component validates each row of the data and sets the ErrorsFound variable to true if an error is found, and builds up a string containing any error details.
Then - based on the ErrorsFound variable - either the data is imported or the error is recorded in a log table.
It gets a bit more tricky when the Excel files are filled in badly enough for the process not to be able to read them at all - for example when text is entered in a date, number or currency field. In this case we use the OnError Event Handler of the Data flow task to record an error in the log but won't know which row(s) caused the problem

How to using the loop and bulk load tasks to insert the name of the csv files being looped?

Description
I have created an SSIS package imports data from hundreds of csv files on a daily bases
I have used the bulk load and foreach loop container
Problem
I have created a column on a database table and wanted to know if it is possible to add the source file name on each row of data.
If you have the filename in a variable (which you could do in the for each loop) then you just use the variable as the data source for the column. Or ther may be a system variable that contains the file name, pole around a bit inthe system varaibles available to you and see.