473,408 Members | 2,832 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,408 software developers and data experts.

Excel automation memory leak

I'm building a reporting system in asp.net which needs an "export to Excel" function. We have Excel 2000 in the office. So I've added a reference to the Microsoft Excel 9.0 Object Library.

Having added "<identity impersonate='true'/>" to my Web.config, I can now create an instance of Excel and manipulate it, more or less as described in KB#306023 ( http://support.microsoft.com/default...b;EN-US;306023 ).

However, each time I do this, I end up with another EXCEL.EXE process staying active. I can't even manually end them (I get an "Unable to terminate process" "Access denied" error).

The core lines look like this:
Excel.Application xl = new Excel.Application();
Excel.Workbooks xwbs = xl.Workbooks;
Excel.Workbook xwb = xwbs.Add( Missing.Value );
Excel.Sheets xwss = xwb.Worksheets;
Excel.Worksheet xws = (Excel.Worksheet)xwss.get_Item( 1 );
Excel.Range xr1 = xws.get_Range( "A1", Missing.Value );
xr1.Value = "Hello world!";
xwb.SaveAs( @"C:\helloworld.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value );
xwb.Close( false, Missing.Value, Missing.Value );
xl.Quit();

The Quit() method doesn't seem to have any effect.

What do I need to do to stop these processes?

Any help will be greatly appreciated!

Nov 18 '05 #1
5 2254
This is a bad idea. Excel is not thread-safe for use in ASP.Net
applications.
I would recommend sending the data down via .csv or some other format that
Excel can natively open & read.
If you need .xls format, I recommend takinig a look at ComponentOne's XLS
component.

The reason ( I think) you can't terminate the process, is because you're not
setting the instance of Excel to nothing when you are done.
xl = nothing;
--Morgan

"RoboSchro" <ro*************@uswitch.nospam.com> wrote in message
news:A2**********************************@microsof t.com...
I'm building a reporting system in asp.net which needs an "export to Excel" function. We have Excel 2000 in the office. So I've added a reference
to the Microsoft Excel 9.0 Object Library.
Having added "<identity impersonate='true'/>" to my Web.config, I can now create an instance of Excel and manipulate it, more or less as described in
KB#306023 (
http://support.microsoft.com/default...b;EN-US;306023 ).
However, each time I do this, I end up with another EXCEL.EXE process staying active. I can't even manually end them (I get an "Unable to
terminate process" "Access denied" error).
The core lines look like this:
Excel.Application xl = new Excel.Application();
Excel.Workbooks xwbs = xl.Workbooks;
Excel.Workbook xwb = xwbs.Add( Missing.Value );
Excel.Sheets xwss = xwb.Worksheets;
Excel.Worksheet xws = (Excel.Worksheet)xwss.get_Item( 1 );
Excel.Range xr1 = xws.get_Range( "A1", Missing.Value );
xr1.Value = "Hello world!";
xwb.SaveAs( @"C:\helloworld.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value ); xwb.Close( false, Missing.Value, Missing.Value );
xl.Quit();

The Quit() method doesn't seem to have any effect.

What do I need to do to stop these processes?

Any help will be greatly appreciated!

Nov 18 '05 #2
Microsoft says that office automation from a non-interactive
environment (asp/services) is not recommended.

Microsoft recommends to use some third party components
for writing excel/word..

check this reference link:
http://support.microsoft.com/?id=257757

--
Hope this helps,
Zeeshan Mustafa, MCSD
"RoboSchro" <ro*************@uswitch.nospam.com> wrote in message
news:A2**********************************@microsof t.com...
I'm building a reporting system in asp.net which needs an "export to Excel" function. We have Excel 2000 in the office. So I've added a reference
to the Microsoft Excel 9.0 Object Library.
Having added "<identity impersonate='true'/>" to my Web.config, I can now create an instance of Excel and manipulate it, more or less as described in
KB#306023 (
http://support.microsoft.com/default...b;EN-US;306023 ).
However, each time I do this, I end up with another EXCEL.EXE process staying active. I can't even manually end them (I get an "Unable to
terminate process" "Access denied" error).
The core lines look like this:
Excel.Application xl = new Excel.Application();
Excel.Workbooks xwbs = xl.Workbooks;
Excel.Workbook xwb = xwbs.Add( Missing.Value );
Excel.Sheets xwss = xwb.Worksheets;
Excel.Worksheet xws = (Excel.Worksheet)xwss.get_Item( 1 );
Excel.Range xr1 = xws.get_Range( "A1", Missing.Value );
xr1.Value = "Hello world!";
xwb.SaveAs( @"C:\helloworld.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value ); xwb.Close( false, Missing.Value, Missing.Value );
xl.Quit();

The Quit() method doesn't seem to have any effect.

What do I need to do to stop these processes?

Any help will be greatly appreciated!

Nov 18 '05 #3
Thanks!

Interesting that this approach in general is considered a bad idea. The first time I got the idea was from another KB article (311194) where Microsoft tell you to do exactly that -- automate an Excel document from an asp.net page.

Ah well.
Nov 18 '05 #4
Thanks.

It does sound like this is a bad idea in general.

Setting the object to Nothing isn't the answer, though. I'm writing in C#, and there's no such statement. You can usually forcibly dispose of objects, but the Excel.Application doesn't allow this.

Nov 18 '05 #5
This article covers the subject in depth:
http://www.aspnetpro.com/NewsletterA...200309so_l.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"RoboSchro" <ro*************@uswitch.nospam.com> wrote in message
news:A2**********************************@microsof t.com...
I'm building a reporting system in asp.net which needs an "export to Excel" function. We have Excel 2000 in the office. So I've added a reference
to the Microsoft Excel 9.0 Object Library.
Having added "<identity impersonate='true'/>" to my Web.config, I can now create an instance of Excel and manipulate it, more or less as described in
KB#306023 (
http://support.microsoft.com/default...b;EN-US;306023 ).
However, each time I do this, I end up with another EXCEL.EXE process staying active. I can't even manually end them (I get an "Unable to
terminate process" "Access denied" error).
The core lines look like this:
Excel.Application xl = new Excel.Application();
Excel.Workbooks xwbs = xl.Workbooks;
Excel.Workbook xwb = xwbs.Add( Missing.Value );
Excel.Sheets xwss = xwb.Worksheets;
Excel.Worksheet xws = (Excel.Worksheet)xwss.get_Item( 1 );
Excel.Range xr1 = xws.get_Range( "A1", Missing.Value );
xr1.Value = "Hello world!";
xwb.SaveAs( @"C:\helloworld.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value ); xwb.Close( false, Missing.Value, Missing.Value );
xl.Quit();

The Quit() method doesn't seem to have any effect.

What do I need to do to stop these processes?

Any help will be greatly appreciated!

Nov 18 '05 #6

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

Similar topics

1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
3
by: Stephen Brooker | last post by:
Hi all, Just playing around a MS how-to sample to work with an Excel file from within C#. Everything is fine and I understand it OK, however when Excel and the application are closed, there is...
0
by: RoboSchro | last post by:
I'm building a reporting system in asp.net which needs an "export to Excel" function. We have Excel 2000 in the office. So I've added a reference to the Microsoft Excel 9.0 Object Library. Having...
5
by: Wenke Ji | last post by:
Hi I open a Excel workbook using below API: Set ExcelServer = CreateObject("EXCEL.Application") Set TargetWorkbook = ExcelServer.Workbooks.Open (CurrentBook) Befor the programm exit , I use...
5
by: RJN | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have...
2
by: Brandon | last post by:
Hi all, I'm currently working on a project where we have a need to expose an Excel spreadsheet on the web as a webservice that needs to be reliable and available 24x7x365. I've implemented a...
6
by: Gunawan | last post by:
Dear All, I have create an excel (COM Object) using this code Excel.Application xls = new Excel.Application(); but I can not remove it from memory although I have using close and quit ...
4
by: =?Utf-8?B?Sm9zaW4gSm9obg==?= | last post by:
I could create MS Excel sheet using ASP.NET 2.0 with C# but it is not being created in some systems, following error occurs when the program compiles : Microsoft Office Excel cannot open or...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.