I'm working on some VB.Net 2008 code that extracts a massive chunk of data from a database and then formats it and sticks it into a text file.

Currently, it builds everything by spooling through a data table and putting the results into an IO.StringWriter, using the .WriteLine method for each record, and then at the end dumps it all out to a text file using the FileSystem.WriteAllText method. Unfortunately, some of the extracts are massive, and it's giving System.OutOfMemoryException errors part-way through the table.

Does anyone know of a way to get around this, short of writing each line out to the text file independently?

Any help would be gratefully received...