Solved

How do I replace CRLF with LF in a .CSV file with a Script Task in SQL 2005 SSIS?

Posted on 2008-10-14
3
1,640 Views
Last Modified: 2013-11-10
I am developing an SSIS package in SQL 2005 that downloads files via FTP and validates them prior to processing. The files are .CSV and generated in a Unix environment, the top line has a Checksum in the first column followed by a line of empty columns followed by the data within the file. The checksum generated is based upon the contents of the file minus the first two lines.

In a script task I am able to read the lines of the file into an array, eliminate the first two lines and calculate the checksum based on the remaining data. My problem is my checksum does not match the checksum provided, most likely because the LF is being replaced with CRLF.

How can I remove the CRLF programatically within VB.NET so I can automatically remove the two lines from the top of the file, eliminate any formating changes Windows may have made (LF to CRLF) and validate the checksum?

This must be an entirely automated process with no intervention of users and also maintain performance as high as possible. My process has 90 minutes to process thousands of these files with 10's of thousands of lines in each file.

Thanks
0
Comment
Question by:Hooznext
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
HoggZilla earned 500 total points
ID: 22717782
VB.NET has three codes to look at:
vbCrLf
vbCr
vbLf

Read the contents of the file into a string
Dim str as String = ...text from file
str = REPLACE(str, vbCrLf, vbLf)
0
 
LVL 1

Author Comment

by:Hooznext
ID: 22720730
HoqqZilla,

I had tried that already and removed it, what I did find my error was...I was reading the file line by line into a string array, I would then begin at line 3 of the array and concatenate the lines into a single string then run the checksum on that string. What I failed to notice was the lines I read out of the file were being stripped of all vbCRLF or vbLF and creating a single string. I added '+ vbLF' to the end of each line in the array then used your suggestion of strFile.Replace(vbCRLF, vbLF) as an extra insurance and now the checksums are working properly.

My day yesterday was riddled with distractions and such that I lost enough focus on the issue to miss something this simple. Once the end of the day arrived and the frustration was high, I turned to the Experts for help. Thanks for the reply, I will award the points as your suggestion made me think about the string AFTER it was reconstructed.

Thanks
0
 
LVL 1

Author Closing Comment

by:Hooznext
ID: 31506100
Thanks again for the suggestion, I needed to walk away from this to gather my thoughts.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question