I noticed this particular line of code when I was profiling my application (which creates a boatload of database insertions by processing some raw data):
myStringBuilder.AppendLine(
string.Join(
BULK_SEPARATOR, new string[]{myGuid.ToString() ...
Bearing in mind that the resultant string is going to end up in a file called via the TSQL command BULK INSERT, is there a way I can do this step faster? I know that getting a byte array is faster, but I can’t just plug that into the file.
The fastest and simplest way would be not to use
BULK INSERTwith a raw file at all. Instead, use the SqlBulkCopy class. That should speed this up significantly by sending the data directly over the pipe instead of using an intermediate file.(You’ll also be able to use the
Guiddirectly without any string conversions, although I can’t be 100% sure whatSqlBulkCopydoes internally with it.)