Excel don't quit in ASP.net Code

  • Thread starter Andreas Friedrichs
  • Start date
A

Andreas Friedrichs

Hi!

I am unable to close my Excel-Task in the following
ASP.net Code:

oMissing = System.Reflection.Missing.Value
objXL = Server.CreateObject("Excel.Application")

objWB = objXL.WorkBooks.add("AuslastungAuftrag.xlt")
objBooks = objXL.Workbooks
objWS = objWB.Worksheets(1) 'i need it for Range-Operations

objXL.visible = False
objXL.Cells(2, 1).Value = "this"
objXL.Cells(2, 2).Value = "is"
objXL.Cells(2, 3).Value = "a test"

objWB.SaveAs(Me.sPathReports & sFileName)

'Closing and to releasing the Com-Objects
While
(System.Runtime.InteropServices.Marshal.ReleaseComObject
(objWS) <> 0)
End While

objWS = Nothing
objWB.Close(False, oMissing, oMissing)

While
(System.Runtime.InteropServices.Marshal.ReleaseComObject
(objWB) <> 0)
End While

objWB = Nothing

While
(System.Runtime.InteropServices.Marshal.ReleaseComObject
(objBooks) <> 0)
End While
objBooks = Nothing

objXL.Quit()

While
(System.Runtime.InteropServices.Marshal.ReleaseComObject
(objXL) <> 0)
End While
objXL = Nothing

'Garbage Collection
GC.Collect()
System.GC.WaitForPendingFinalizers()


After calling this Code 5-times, 4 Excel Processes will be
closed and one is still remaining.
Without the "ReleaseComObject"-Call none of the processes
will be closed.

BUT: Sometime it works properly. Yesterday it worked fine -
then i added some ADO-Code to fill the Excel-Table with
SQL-Data. After this i became the problem. Is it
magic.... :)

Any Idea?
Thx, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top