I really REALLY hope that someone could help me.

I have to pass almost 400.000 records from a database to a textfile
Because of this amount the extension of the textfile is just something
I made up ...(.you_name_it)
I get an error while writing the data to the file at +/- 9000 records.
The error = Exception of type 'System.OutOfMemoryException' was thrown
And I don't know the solution :(

This is the peace of code I use for writing the records to the file.


         this.path_to_file =
         ConfigurationManager.AppSettings["ExportDir"] +
DateTime.Now.ToString(ConfigurationManager.AppSettings
["Export_FileName"]) + ConfigurationManager.AppSettings
["Export_Extension"];


         FileStream fm = new FileStream
            (this.path_to_file, FileMode.Create, FileAccess.ReadWrite,
FileShare.ReadWrite);

         StreamWriter sw = new StreamWriter(fm, Encoding.Default);

         List<Export> exportRecords = null;

         exportRecords = ExportList();
         try
         {
             int i = 0;
            foreach (Export ex in exportRecords)
            {
                sw.Write(ex.ExportLine());
               sw.Write(sw.NewLine);
               sw.Flush();
               exportlines += ex.ExportLine() + "\n";
                i++;
            }
         }
         catch (Exception exc)
         {
            Log.Write(exc.Message);
         }

Reply via email to