473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP.NET: Can't Kill EXCEL.exe with Office PIA

I have been trying to use the Office PIA's to write an ASP.NEt page to:
1. Open a template workbook
2. Populate some data
3. Save the file back to the server
4. Quit Excel and free up Memory

I have been able to do all of the above steps except #4. Each time
Excel.exe persists in memory. I have already referred to Q317109 "Office
application does not quit after automation from Visual Studio .NET client"
without much luck.

I've tried stripping down the Office code to see where this hang is coming
from exactly and found the following:

WORKS: The following DID release Excel.exe:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

ERROR: When I augment it to the following however, Excel.exe continues to
hang:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim wkBook As Workbook = xlApp.Workbooks.Open("C:\test.xls")

xlApp.Workbooks.Close()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wkBook)
wkBook = Nothing

xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

If anyone could explain why this might be happening, it would be greatly
appreciated. It seems as if as soon as I get into working with a workbook,
Excel.exe is stuck in memory. Rather than a specific fix for the above, I'm
just looking to better understand the dynamics/rules here for avoiding this
problem.

Thanks in advance,

Chris Frohlich

Apr 13 '06 #1
2 2504
your problem is the line.

Dim wkBook As Workbook = xlApp.Workbooks.Open("C:\test.xls")

because .net needs wrapper to call com objects it really turns into

Dim wkBook As Workbook
dim tmp as WorkBooks
tmp = xlApp.Workbooks
wkBook = tmp.Open("C:\test.xls")

the tmp variable has a com ref that will not be released until its garabage
collected. the rule you should use is never use 2 dots with com objects.
alway create a tmp, and call ReleaseComObject() on the tmps.
-- bruce (sqlwork.com)


"ChrisFrohlich" <Ch***********@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
I have been trying to use the Office PIA's to write an ASP.NEt page to:
1. Open a template workbook
2. Populate some data
3. Save the file back to the server
4. Quit Excel and free up Memory

I have been able to do all of the above steps except #4. Each time
Excel.exe persists in memory. I have already referred to Q317109 "Office
application does not quit after automation from Visual Studio .NET client"
without much luck.

I've tried stripping down the Office code to see where this hang is coming
from exactly and found the following:

WORKS: The following DID release Excel.exe:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

ERROR: When I augment it to the following however, Excel.exe continues to
hang:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim wkBook As Workbook = xlApp.Workbooks.Open("C:\test.xls")

xlApp.Workbooks.Close()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wkBook)
wkBook = Nothing

xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

If anyone could explain why this might be happening, it would be greatly
appreciated. It seems as if as soon as I get into working with a
workbook,
Excel.exe is stuck in memory. Rather than a specific fix for the above,
I'm
just looking to better understand the dynamics/rules here for avoiding
this
problem.

Thanks in advance,

Chris Frohlich

Apr 14 '06 #2
Besides thorough COM cleanup I still sometimes get stuck excel process so I
implemented this routine.

//kill EXCEL com processes
System.Diagnostics.Process [] PROC = Process.GetProcessesByName("EXCEL");
foreach(System.Diagnostics.Process PK in PROC)
{//User excel process always have window name
//COM process do not.
if(PK.MainWindowTitle.Length==0)
PK.Kill();
}


"bruce barker (sqlwork.com)" wrote:
your problem is the line.

Dim wkBook As Workbook = xlApp.Workbooks.Open("C:\test.xls")

because .net needs wrapper to call com objects it really turns into

Dim wkBook As Workbook
dim tmp as WorkBooks
tmp = xlApp.Workbooks
wkBook = tmp.Open("C:\test.xls")

the tmp variable has a com ref that will not be released until its garabage
collected. the rule you should use is never use 2 dots with com objects.
alway create a tmp, and call ReleaseComObject() on the tmps.
-- bruce (sqlwork.com)


"ChrisFrohlich" <Ch***********@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
I have been trying to use the Office PIA's to write an ASP.NEt page to:
1. Open a template workbook
2. Populate some data
3. Save the file back to the server
4. Quit Excel and free up Memory

I have been able to do all of the above steps except #4. Each time
Excel.exe persists in memory. I have already referred to Q317109 "Office
application does not quit after automation from Visual Studio .NET client"
without much luck.

I've tried stripping down the Office code to see where this hang is coming
from exactly and found the following:

WORKS: The following DID release Excel.exe:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

ERROR: When I augment it to the following however, Excel.exe continues to
hang:
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim wkBook As Workbook = xlApp.Workbooks.Open("C:\test.xls")

xlApp.Workbooks.Close()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wkBook)
wkBook = Nothing

xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp)
xlApp = Nothing

If anyone could explain why this might be happening, it would be greatly
appreciated. It seems as if as soon as I get into working with a
workbook,
Excel.exe is stuck in memory. Rather than a specific fix for the above,
I'm
just looking to better understand the dynamics/rules here for avoiding
this
problem.

Thanks in advance,

Chris Frohlich


Apr 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Denis Brkljacic | last post by:
Hello, Please, if enaybody could help a little bit... Namely, I need to build C# ASP.NET Web that opens some Template.xls, write something to it and then closes it (and releases the objects)....
10
by: Lars-Erik Aabech | last post by:
Hi! This issue have been discussed a lot, but I haven't found a solution that applies to ASP.NET. I have a library which does some operations on Excel documents, and it will be used in an...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
3
by: kunal.kewalramani | last post by:
I'm opening an Excel file using ASP.NET, but Excel process remains it is not killed, I tried killing it by using Quit() that is also not working, if anybody have any solution for this please help me...
6
by: Luke Vogel | last post by:
Hi all ... could someone point me in the right direction for programming office applications (specifically excel) using vb.net? Can vb.net replace or enhance VBA that comes with the office suite?...
3
by: James Wong | last post by:
Dear all, I have an old VB6 application which can create and access Excel object. The basic definition statements are as follows: Dim appExcel As Object Dim wkb1 As Excel.Workbook Dim wks1...
3
by: Mitchell Vincent | last post by:
Does anyone have some good examples of Excel automation with (VB).NET? I have some Excel spreadsheets that a customer needs parsed out but I've never tried to use Excel programatically before! ...
0
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3:...
2
by: Nicholas Dreyer | last post by:
The following error Run-time exception thrown : System.Runtime.InteropServices.COMException - Error loading type library/DLL. happens while running the code listed at the bottom of this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.