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,590 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now