|
-
June 8th, 2012, 04:42 PM
#2
Re: Efficient way to do validation
I do very similar stuff at work all day. I actually have a dll that has an entire flat file validation. The dll calls for a custom XML made for individual files I insert into a database. In my XML it has <FieldSeparator/> <TextQualifier/> <FixedWidth/> <FirstRowIsHeader/> and a couple other smaller features. Then I have
<Columns>
<Column name="" index="" maxLength="" minLength="" width="" required="" trim="" regex="" />
are among my column validations. So I have an Xmlreader that grabs all this info set within the XML, and goes through my file. I actually use a For loop with int's (start, end, cursor) and grab each value separated and checks for data within qualifiers if there are any. If it fails the regex that was set in the XML my validator grabs and holds the errors, then after the file is completely processed it sends it to a text file, with the specific error that caused it to fail, for example: Column Count Mismatch, Failed Regex, Length of data is too long = ##, etc.
Very easy to validate the file, now, for the SQL issue, I do not recommend loading tables into memory. Though, the reason I don't is because some of the tables I work with can be anywhere between 1mb - 2gb+ But to the tables I need to add records that do not exist, I have an automation/SQL job, that is ran daily every morning. That I have a file assigned to a TaskID, the validation XML is in a column, couple other columns. So when the job kicks off it grabs all this info from SQL and uses and SSIS package, so before the data hits SSIS it validates, if it fails, that task fails. If it passes, continues to the SSIS package and from there, a multitude of ways to look-up data in SQL or update tables and output a log of what already existed, etc.
Well that's my two cents, lol
Last edited by Deranged; June 10th, 2012 at 01:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|