SSIS: Manage broken Data Flow Task because Excel column name changed? - ssis

I have a simple SSIS package that exports an Excel file to a csv file: each column in the Excel is mapped to a column in the csv.
Assuming that a column name in the Excel file changes, is it possible to gracefully manage this error so that it's marked as "failure" in the Precedence Constraint Editor and then moves on to the Failure task?
As it stands, if I run the package with a different column name, I'll get this error and everything stops:
I'd like to edit it so that if the column changes, it goes to the "Send Failure Email" task.
Is this possible?

I believe what you are looking for is this.
This will then only validate when it reaches the task and not when the package initializes.

Related

Ssis empty excel columns causing error

Using Microsoft Visual Studio Community 2015.
Goal of project
-create "*\temp\email" directory
-start program to extract all emails that include xls attachments to the previously created folder
-use for each loop to cycle through each file in the folder, process, and shift to sql table.
The problem I am running into is caused by either a blank excel document (which is occasionally sent from a remote location) or some of the original xls reports only contain 5 columns instead of 6 that I have mapped now. Is there any way to separate files that include the correct columns from those that do not match?
** as Long as these two problems do not exist I can run the ssis package and everything runs without issue.
Control flow;
File System Task (creates directory --->Execute Process Task (xls extraction)-->ForEach Loop(Data flow Task "email2Sql")
Data Flow;
Excel Source (uses expression ExcelFilePath,#user:filepath) delay validation ==true
(columns are initially set to f1-f6 and are mapped to for ex. a,b,c,d,e,f. The Older files that get mixed in only include a,b,c,d,e.) This is where I want to be able to separate the xls files
Conditional Transformation split (column names are not in row 1, this helps remove "null" values)
Ole Db destination (sql table)
Sorry for the amount of reading, but for the first post I tried to include anything that I thought may be relevant.
There are some tools out there which would allow you to open the excel doc and read it. However, I think the simplest thing to do would be to use SSIS out of the box:
1 - add a file system task after the data flow which reads the file.
2 - Make the precedence constraint from the data flow to the file system task "failure." This will cause that to only fire when the data flow task fails.
3 - set the file task to move the "bad" files to another folder
This will allow you to loop through all the files and move the failed ones. Ultimately, the package will end in failure. If you don't want that behavior you can change the ForceExecutionResult property to be success. However, it might be good to know that there were problems with some files so that they can be addressed.
m

How to do File System Task in SSIS depending on Result of Data Flow

I'm writing a (what I thought to be a) simple SSIS package to import data from a CSV file into a SQL table.
On the Control Flow task I have a Data Flow Task. In that Data Flow Task I have
a Flat File Source "step",
followed by a Data Conversion "step",
followed by a OLE DB destination "step".
What I want to do is to move the source CSV file to a "Completed" folder or to a "Failed" folder based on the results of the Data Flow Task.
I see that I can't add a File System step inside the Data Flow Task, but I have to do it in the Control Flow tab.
My question is how do I do a simple thing like assign a value to a variable (I saw how to create variable and assign them a value at the bottom pane of Data Tools (2012)) depending of if the "step" succeeds or fails?
Thanks!
(You can tell by my question that I'm an SSIS rookie - and don't assume I can write a C# script, please)
I have used VB or C# scripts to accomplish this myself. Since you do not want to use scripts I would recommend using a different path for the project to flow. Have your success path lead to moving the file to completed and failure path lead to moving the file to failed. This keeps it simple and accomplishes what you are looking for.

SSIS package No data issue

Hi I have created basic SSIS package that reads data from Flat Txt file using comma separated and inputs into MS SQL database. Package is working alright but when there is no data in the flat file Then it displays message "No records found." when ever flat file has this message my package stops working as column mapping distracts. Any idea to solve this issue.
Note: Flat file is generated by some automatic tool I cant change it.
Sample File:
====================== Here is output ================
You can see Both Lookup Match and No Lookup are running.
you can add a data flow to count the records before the main data flow. Execute main only if there are more than one record on the flat file. The control flow would look like this:
Keep a separate flow when an error occurs and log into flat file
Refer to this for more details:
http://sqlknowledgebank.blogspot.com/2013/04/ssis-data-flow-error-handling.html
It is similar to exception handling in any of the programming lanaguages.
If the exception is unhandled , then package terminates abruptly.
Inorder to avoid that, we need to catch the exception and log it .
This avoids abrupt stopping of packages and it exeutes sucessfully.
I just need to update status of all the records which are not in the flat file so I used OLEDB command on the top of my package and updated status of all records in the table. Rest I kept my package as it is(without any changes).

Can we have the mapping for OleDB Source to Excel Destination at runtime rather than at design time?

I am trying to create a SSIS package that will export csv data to an excel file. This package will be called up from C# giving the csv file as input to the package. I am quite new to SSIS and I've been able to produce the expected result with same headers.
I went with the following approach -
Script task - created scripts from the csv headers to create temp table, bulk insert, excel table scripts.
Execute SQL Task - created a temp table in database
Execute SQL Task - Bulk insert csv data into table
Execute SQL Task - Create Excel file
Data Flow Task - OleDB Source to Excel Destination
Execute SQL Task - Drop the temp table created
The challenge I am facing is that my csv may have different headers (both text and number of headers may be different). And I want a single package to serve this purpose.
With the headers being different, the mapping between OleDB Souce to Excel Destination in step 5 above is not working for dynamic headers and is giving unexpected results in the excel output. Is there any way these mappings can be decided at runtime and not at design time.
I don't believe that you can specify the columns or column mappings of a Data Flow at SSIS runtime. You could build the SSIS package on-the-fly, which would allow your C# code to create the column mappings, but the mappings have to be created before the package can run. See Building Packages Programmatically in MSDN for details.
On the other hand, if all you're trying to do is convert a CSV file into an Excel spreadsheet, it would seem logical to me to use the Workbook.SaveAs method of the Office object model.

SQL Server Integration Services - Redirecting failing records to flat file destination

Observe the following snippet of an SSIS package:
Both of the Flat File Destination tasks on the right are configured to write to the same Flat File Connection Manager, because I want all the failing records to be redirected to the same file regardless of which task caused them to fail.
SSIS is complaining on the second Flat File Destination, saying that the output file is in use by another process.
Is my stated goal simply impossible, or is there a way to redirect all failing records to the same output file?
No, you cannot do it this way. You need to use an Union All to combine the output before writing the output from different sources/transformations to the same destination.
If you have a process flow as described in the question, the package will fail on the second destination component.
The error message would be `The process cannot access the file because it is being used by another process.
To fix the issue, add a Union All transformation that will take the error output from Derived Column transformation and combines it with the error output from OLE DB Destination and the output of Union All transformation is then passed on to the Flat File destination.
Hope that helps.