ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel don't quit in ASP.net Code (https://www.excelbanter.com/excel-programming/287051-excel-dont-quit-asp-net-code.html)

Andreas Friedrichs

Excel don't quit in ASP.net Code
 
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.ReleaseCom Object
(objWS) < 0)
End While

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

While
(System.Runtime.InteropServices.Marshal.ReleaseCom Object
(objWB) < 0)
End While

objWB = Nothing

While
(System.Runtime.InteropServices.Marshal.ReleaseCom Object
(objBooks) < 0)
End While
objBooks = Nothing

objXL.Quit()

While
(System.Runtime.InteropServices.Marshal.ReleaseCom Object
(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



All times are GMT +1. The time now is 01:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com