Click here to Skip to main content
15,884,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating an SSIS package to load .XLSX files in a SQL Server staging table. I need to control the columns number in my Excel source file in order to have exactly the same columns in both source and destination. The issue is that even when I add manually more columns in my Excel source files the data flow task succeeds which is not what I need because it's a technical constraint to me. It should fail, because I need to redirect failure and rename the file.


What I have tried:

I thought about counting columns in my source file and compare it with the number of columns in destination, but this is not really the purpose, I want to use Excel structure passing by SSIS.
Posted
Updated 17-Jan-19 1:11am

1 solution

You're going to have to write a script task to do that, and handle the import manually. I have an article here that loads excel and csv files into DataTable objects, which can then be used to import into into a database.

Here's the original article, which is a tool for adding SQL Agent functionality to SQL Express.

SQLXAgent - Jobs for SQL Express - Part 1 of 6[^]

And here's another article that breaks out the excel/csv importing part for easier inclusing in your own projects (I used this code in several SSIS projects):

CSV/Excel File Parser - A Revisit[^]
 
Share this answer
 
v2
Comments
Member 12887760 17-Jan-19 9:43am    
@John Simmons,
Thank you for your answer, but I'm not using a SQL Epress. I have complete SQL instance with Licence. In this case I don't see why using VB script to import data instead of SSIS ? can you give more explanation please?
Thankk you upront.
#realJSOP 17-Jan-19 9:59am    
I cited the first article so you could see how I used it to do what you want. It will create a table based on the contents of the file being imported.

The second article cited simply breaks that importer code to make it easier to include in your own projects.

Even if it doesn't exactly fit your requirements, be a programmer and bend it to your own nefarious designs.

I don't do anything in VB (much less VB script). Since SQL Server 2008, you can use C# to write a SSIS script task.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900