Wednesday, February 18, 2015

OleDB Alternative

Had an interesting issue come up using OleDB worth noting...

I was working on a project to import data from a tab delimited file into SQL using SqlBulkCopy.  The OleDb file count matched the record inserted file count but comparing the output to the old application with the same data produced different results.

I dropped the file into Excel and it also showed the same results as OleDb.  However, when opened in Notepad++ it became apparent that OleDb and Excel (presumably using OleDb to import the file) was merging some of the row data into a description column in the file.

So from all appearances it looked like the process was working but in reality it wasn't.

The workaround was to replace using OleDb with TextFieldParser.  You can find plenty of examples of how this works by searching for it.  You will need to add a reference Microsoft.VisualBasic.FileIO which is odd but that's where they put the TextFieldParser.

Once I implemented this change to read the file into a DataTable the results matched the old application.