Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close Excel process from ASP.NET

Status
Not open for further replies.

snoopdougie

Programmer
Jan 21, 2004
12
0
0
ZA
I am running an aspx page which fetches a formula from an excel sheet. I open an excel application object, open a workbook, then close them again. When I check the Task manager, the Excel process i started when i created the new application is still runnning. This is a problem, because after a few refreshes, my system is crippled with multiple open excel processes. Does anyone know how to remedy this?

My code is as follows:

Dim oXL As New Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet

oWB = oXL.Workbooks.Open(strpath)
oSheet = oWB.ActiveSheet
strFormula = oSheet.Range(strAddress).Formula
oWB.Close(False, strpath)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB)
oXL.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
oWB = Nothing
oXL = Nothing
oSheet = Nothing

I know my close object code is overkill, but no matter what I have tried, the Excel process is still running in the task manager.

If I don't open a workbook, then even a simple oXL.Quit terminates the process. But once I open a workbook with the oXL object, no matter what I try, the process cannot be ended.


I am considering a few options --

1. Using an API call to kill the process

2. Try to use the Primary Interop Assemby for XL, instead of the assemblies generated by default.

3. Use XL ODBC driver to get value from sheet (I know I can get a value from a cell this way, I'm not sure I can get a formula)

4. Maybe just keep the Excel object open (global), and re-use it each time, so that even if i can't close it, there is only one Excel process created.


Incidentally, problems of this sort only seem to appear in ASP.NET. This code works fine in VB.NET.

Can anyone help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top