I was using the LumenWorks utility to import a text file into SQL the other day. LumenWorks is a free sourcecode tool over at CodeProject http://www.codeproject.com/KB/database/CsvReader.aspx
I was running a bulk import using the csvreader as an input stream for a SQL bulk copy.
source.LumenWorks.Framework.IO.Csv.CsvReader csvReader =
new LumenWorks.Framework.IO.Csv.CsvReader(strm, true);
string[] Headers = csvReader.GetFieldHeaders();
PrepTable(Headers, ReportId, TableName, conn);
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn))
{
bulkCopy.DestinationTableName = TableName;
bulkCopy.BulkCopyTimeout = 60;
bulkCopy.BatchSize = 10000;
bulkCopy.WriteToServer(csvReader);
bulkCopy.Close();
}
I was running the application in VS2008 but one of my fields was too short to accomodate the text, so the program errors on the bulkCopy.WriteToServer(csvReader) line and tells me it has a problem. All is fine but when I press stop to update the appropriate code SQL Server completely crashes dead with a 17052 error (Event Log said it cannot find the description for that error). I did this a few times and confirmed that is exactly what is happening. Not sure what would happen if I am running as an application rather than debugging in VS.
Solution - A simple try catch around the code fixed the problem. The first version was a rush job without a try catch. Somewhere in .net's management with a try - catch the crash is avoided which is a good thing.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment