Hello Friends,
Urgent help required...
I am developing a Web Application using ASP.Net 2.0 and C#, my data base is ORACLE 9i. Previously everything was going right, but now as the data increases and the retrieving is become headache for me. Previously i was showing this data in the third party grid i.e. FARPOINT Spread. It happens with the spread too. so i write a program to convert the Generic List into excel sheet. This works fine on local (XP Professional 2 GB RAM and all) but once i deployed this application on the server (Win server 2003 12 GB RAM with 3GB Virtual Memory set) it gives me error that 'System.OutOfMemoryException'.
I checked that data is coming till UI layer from Business layer but still why it is throwing error. Couldn't make it out. And i need solution for this ASAP.
Thanks in advance.
Code to write excel sheet -
private
void FpLoadEditData(ArrayList userName, ArrayList siteId, string from, string to){
oXL =
new Application();oXL.Visible =
false; //Get a new workbook.oWB = (
_Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));oSheet = (
_Worksheet)oWB.ActiveSheet; //System.Data.DataTable dtGridData = ds.Tables[0]; int iRow = 2; // Setting Column name for Sheet int colCount = QiSpread.ActiveSheetView.Columns.Count; int colHeaderIndex = 1; for (int j = 0; j < colCount; j++){
oSheet.Cells[1, j + 1] =
ConfigurationSettings.AppSettings["colHead" + colHeaderIndex];colHeaderIndex++;
}
for (int rowNo = 0; rowNo < vzmLst.Count; rowNo++){
//if (rowNo < 150) //{ for (int colNo = 0; colNo < QiSpread.ActiveSheetView.ColumnCount; colNo++){
PopulateSheet(oSheet, iRow, colNo, vzmLst[rowNo]);
}
iRow++;
//} //else // rowNo = vzmLst.Count;}
if (vzmLst.Count > 6000)Session.Timeout = 15;
oRng = oSheet.get_Range(
"A1", "IV1");oRng.EntireColumn.AutoFit();
oXL.Visible =
false;oXL.UserControl =
false; string strFile = string.Empty; if (Request.Params.Get("__EVENTARGUMENT") != null &&Request.Params.Get(
"__EVENTARGUMENT").ToString().ToUpper().Equals("EDITDATA")){
strFile =
"VzMEditData_" + loginName + from + "TO" + to + "_" + DateTime.Now.Second.ToString() + ".xls"; //strFile = "VzMEditData" + from, to DateTime.Now.Ticks.ToString() + ".xls";}
else if (Request.Params.Get("__EVENTARGUMENT") != null &&Request.Params.Get(
"__EVENTARGUMENT").ToString().ToUpper().Equals("VIEWDATA")){
strFile =
"VzMViewData_" + loginName + from + "TO" + to + "_" + DateTime.Now.Second.ToString() + ".xls";}
//string strFile = "report" + DateTime.Now.Ticks.ToString() + ".xls";//+oWB.SaveAs(strCurrentDir + strFile,
XlFileFormat.xlWorkbookNormal, null, null, false, false, XlSaveAsAccessMode.xlShared, false, false, null, null, null); // Need all following code to clean up and remove all references!!!oWB.Close(
null, null, null);oXL.Workbooks.Close();
oXL.Quit();
Marshal.ReleaseComObject(oRng); Marshal.ReleaseComObject(oXL); Marshal.ReleaseComObject(oSheet); Marshal.ReleaseComObject(oWB);Session.Add(
"fileUrl", strFile);}
To display the generated excel -
private void GetExcel()
{
if
(Session["fileUrl"] != null && Session["fileUrl"].ToString() != string.Empty){
Response.ContentType =
"application/vnd.ms-excel";Response.AppendHeader(
"Content-Disposition", "attachment; filename=" + Session["fileUrl"].ToString());Response.TransmitFile(Server.MapPath(
".") + "\\EditViewDataFiles\\" + Session["fileUrl"].ToString()); HttpContext.Current.ApplicationInstance.CompleteRequest();Response.Flush();
Response.Close();
}
}
Regards,
Abhijeet
AbhijeetPosted Apr 21, 2009, 2:34 AM
I'll try to implement this. But the requirement is that user wants to see the records he fetched for the selection criteria, hence we are working out on it.
Anyways thanks for you reply and suggestions.
Will let you know the progress and new development for the same.
Regards,
Abhijeet
Vijaya KadiyalaPosted Apr 17, 2009, 12:54 PM
Hi instead of displaying the records in xl file loop thru all the records in the code and finally display the count in xls. This is to verify wheather the issue is with Excel or the code which is populating the excel.
Thanks -- Vijaya Kadiyala
www.DotNetVJ.com
AbhijeetPosted Apr 17, 2009, 1:56 AM
Thank you very much for you reply.
Actually i am getting more than 10k ROWS. This is working fine on Local machine, but once i deploy it on the server (which is mentioned in my POST) then it creates a problem. Say almost after writing 5k rows it throws error on Server.
Regards,
Abhijeet
Vijaya KadiyalaPosted Apr 16, 2009, 1:26 PM
Hi Abhi.
how many records you are fetching? Did you try with limiting No.Of records displaying in UI layer??like 100..200..300!!!
Can you debug in this way and let us know what is the figure.
Thanks -- Vijaya Kadiyala
www.DotNetVJ.com