SSIS vs Text File Importing – III
In my previous posts << SSIS vs Text File Importing –I >> and << SSIS vs Text File Importing –II >> , we discussed about the Row Delimiter issue of SSIS while dealing with text files and the workaround for the same. In this post I will show you how to achieve the same through SSIS package.
Step1: Open BIDS (Business Intelligence Development Studio), and create a solution for Integration Services.
Step2: Drag a foreach Loop Container task from the toolbox, to the package and rename it to some meaningful words.
Step3: Double click the Foreach Loop container, and Click on “Collection” at the left pane.
Step4: Select “Foreach File Enumerator” from the Enumerator list and configure the values as shown below.
Step 5: Click on the “Variable Mappings” and create a string variable to store intermediate text file path for each iteration of the loop. Assign the default value to one of the text files to avoid any validation error.
Step 6: Click OK and drag one “script task” inside the “foreach loop container”.
Step 7: Double click the “Script Task” and select “Microsoft Visual Basic 2008” under “Script Language” text box.
Step 8: Click on the ellipse button beside “ReadOnlyVariables” and check the variable named “User::TextFilePath”.
Step 9: Click on the “Edit Script …” button and paste the below code inside the Main function.
Script Task Code in VB .Net ExpandThe above code is written in VB which will open the text file in Excel Application and will save it. This in turn reformats the missing tabs in the text file.
Step 10: Save the file and close it. Press OK.
Step 11: Drag a data flow task inside the “Foreach Loop Container” and double click it.
Step 12: Create source and destination connection manager for data transformation.
Step 13: Drag Flat file source for Text file and OLEDB destination for SQL table and configure it for a transformation to occur.
Step 13: Right click on the text file source connection manager, and click on “Properties”. On the “Properties” pane click on the ellipse button beside “Expressions”.
Step 14: On the “Property Expressions Editor”, select “Connection String” under the “Property” drop down box and click on ellipse button under “Expression”.
Step 15: On the “Expression Builder” dialog box, drag the variable “User::TextFilePath” inside “Expression:” text box and click on “Evaluate Expression” button. Click OK.
Step 16: The overall package should look like below:
Now run the package. After it got completed successfully, check the data in the destination table.
Use the below query:
SELECT [CarCompany] ,[CarBodyType] ,[CarName] ,[EngineType] ,[EMI (INR)] ,[LoanType] ,[Interest Rate] FROM [dbo].[Car_Info]
Output:
We got exactly 9 rows and the data is properly aligned.
Hence the problem got resolved by adding a simple script task code that reformats the text file before loading it into database.
Note: Download the Full SSIS solution from here for FREE. ![]()










what if the input file is not CSV but it is ! separated ?
Thank you arun, this is an excellent solution. I’m new to all this but really appreciate the idea to solve the delimiter issue.
I had followed same solution given by you. My requirement is that flat file source task should give error if then file is empty or all the rows are does not contain required no of mandatory column data
well rajashekar,
in that case go for script transformation task, it will be much easier.
Kindly, raise your issues or problems in the FORUM area. You will definitely get some solution from our active users.
FORUMS:
http://www.sqllion.com/forums/
What if this solution needs to be deployed on Production and the Server does not have excel installed? Will EXCEL component be stable, if there are 1000+ files being processed within an hour with requirement of Zero failures?
Hi Taleleuma,
Excel component i.e. excel installation is needed if you going through this method.
If your deploying server doesn’t have EXCEL, then you need to rely on “Source Script Component” (one of the transformation) where it can be handled explicitly through coding. And then its totally depends on the logic that is used to parse the rows and columns, to know whether it is able to process 1000+ files in one hour or not.
–Arun
Thank you Sqllion!!!!
Excel uploaded the CSV file correctly but not in SSIS. I have been trying to figure out how to solve this and it’s been three days… Almost killed my self.
With your solution, the whole process can be automatic now from FTP to generating a report.
Thank you Thank you Thank you….
Hi Sqllion..
Well, I still have problems loading CSV file.. I have been trying to search the solution but couldn’t.
You have used the script to open and save CSV file. Is there any way to delete few columns and save as excel file?
I have been looking for the way to do it for 3 days now… can’t find it.
Merry Christmas~
- Mark