using excel.2003 from ASP.NET. Excel.Application unloading?

  • Thread starter Nikolay I.Nikolskiy
  • Start date
N

Nikolay I.Nikolskiy

Hi!
I have the following problem.
I need to open and read data from Excel.2003 file from ASP.NET web page.
To open Excel I use the following code:
Excel.Application myExcel = new Excel.Application();

....

myExcel.Quit();

myExcel = null;

It is loading EXCEL.EXE into memory, but Quit() does not unload it .

It was ok when I did the same from ASP page.



Could someone help?

Thank you, Nikolay.
 
B

Bill Cooter

Nikolay,

Have you ran in debug to insure that the .quit is actually being executed?

Bill
 
M

Mark Bower [MSFT]

Server-side automation is not a supported scenario for Excel. This article
explains why: http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757


Instead you should try using ADO.NET to access your data. This article
explains how:

HOW TO: Query and Display Excel Data by Using ASP.NET, ADO.NET, and Visual
C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;306572

Hope that helps.

--
Mark Bower
Microsoft
http://blogs.msdn.com/bowerm

This post is provided 'as-is' without warranty and confers no rights.
 
N

Nikolay I.Nikolskiy

I was thinking about this but really I need to read different typed data,
but ADO uses the same type for each column.
I already use Excel automation in ASP. It works fine. Everything is also
fine in ASP.NET but only one thing is not working, I can't close excel.exe.
I was trying to use different settings that swtches off dialogs, but it did
not help.
myExcel.DisplayAlerts = false;

myExcel.AskToUpdateLinks = false;

myExcel.AlertBeforeOverwriting = false;

myExcel.DisplayInfoWindow = false;

myExcel.FeatureInstall = Office.MsoFeatureInstall.msoFeatureInstallNone;
 
N

Nikolay I.Nikolskiy

here is the answer - I hope it can help to another people.
I've found some info in the microsoft KB
http://support.microsoft.com/default.aspx?scid=kb;en-us;317109&Product=vbNET
It is necessary to release myExcel object. But really it was necessary to do
it twice :)

Code looks like the following:

Excel.Application myExcel = new Excel.Application();

....

myExcel.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel) ;

System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);

myExcel = null;

GC.Collect();

I think better to do release until its result is more than 0, something like
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel)>0);
 

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