are placed in memory and must be destroyed via ReleaseComObject as you have
done with your NAR method, but the line:
objExcel.Workbooks.Open(Page.MapPath("reports\BLCo st.xls"))
could be the culprit since the Open method returns a reference to a Workbook
object that you haven't assigned a variable to. Since you have no variable
to explicitly use to destroy the reference, the reference counter for that
object can't get to zero and therefore Excel won't close.
You should always explicitly assign a variable to all references, that means
any method or property call that returns an object.
-Scott
"Raymond Chiu" <rc******@yahoo.com.hkwrote in message
news:ed**************@TK2MSFTNGP04.phx.gbl...
Dear All,
I have the problem which exists for several months and cannot find the
solution in the web, I see others also have the same situation but they
are also not solved.
It is excel object which still remain in the process in the task manager
in the server. Another project does not have this problem and they are on
the same server. I have tried to change from win2000 server to win2003
server, from ms office 2003 to ms office 2007. Excel still remain in the
process in the task manager. Although it would not affect another excel
running of another records, I need to clear the excel session everyday in
the server.
You can try using the attached excel file to see whether it would cause
the same problem in your computer. Please Let me know and your ideas.
Appreciate for your help!!!!
---------------------coding -----------------------------------------------------------------------------------
Dim objExcel As New Excel.Application
Dim objSheet As Excel.Worksheet
objExcel.Workbooks.Open(Page.MapPath("reports\BLCo st.xls"))
objExcel.DisplayAlerts = False
objSheet = objExcel.Sheets("Form")
objSheet.Copy(After:=objSheet)
objSheet = objExcel.ActiveSheet
.................................................. .....
objExcel.Sheets("Form").Delete()
objSheet.SaveAs(Page.MapPath("..\out\" & sFileName))
NAR(objSheet)
objExcel.Workbooks.Close()
NAR(objExcel.Workbooks)
objExcel.Quit()
NAR(objExcel)
GC.Collect()
---------------end of
sub-----------------------------------------------------------------
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch ex As Exception
Dim remarklabel As Label
remarklabel = CType(FormView1.FindControl("remarklabel"),
Label)
remarklabel.Text = remarklabel.Text + ex.ToString()
Finally
o = Nothing
End Try
End Sub