Insufficient memory issues in excel file download

Feb 3, 2012 at 9:07 AM
Edited Feb 3, 2012 at 9:20 AM

Hi,

What is the solution to fix insufficient memory issues in asp.net. I am trying to download and heavy excel file from asp.net. The file is approx 24 MB and has close to 65,000 records and 100 columns. It is running fine for a while then i am facing memory insufficient issues in server.

ERROR: Message: Could not save the workbook.Insufficient memory to continue the execution of the program

I tried closing and releasing all resources but nothing worked? I tried playing with web config settings like

Tried decreasing the requestLengthDiskThreshold value from initial value of 99999999

< httpruntime useFullyQualifiedRedirectUrl="true" requestValidationMode="2.0" maxRequestLength="99999999" requestLengthDiskThreshold="1024" executionTimeout="99999999" />

 finally
        {  //Close the workbook and dispose the object

            workbook.Close();
            workbook = null;
            // kill the right process after export completed
            KillExcel();

            System.Runtime.InteropServices.Marshal.CleanupUnusedObjectsInCurrentContext();

            GC.WaitForPendingFinalizers();
            GC.Collect();

        httpResponse.End();

        }

  private void KillExcel()
    {
        Process[] AllProcesses = Process.GetProcessesByName("excel");

        // check to kill the right process
        foreach (Process ExcelProcess in AllProcesses)
        {
            if (myHashtable.ContainsKey(ExcelProcess.Id) == false)
                ExcelProcess.Kill();
        }

        AllProcesses = null;
    }