Interesting Problem using Excel in a VB .NET Web Service

S

Suzanne Barclay

I've a problem with a VB .NET web service.

After writing code (see below) I run the webservice &
invoke the method - it works but when I look at Task
Manager, EXCEL.EXE still hangs around!!! (ie. each time
I invoke test, a new instance of excel.exe appears)

NOTE: 1. Same code in a console app works fine.
2. If I recompile web service, all instances of
excel.exe disappear from TaskManager

Steps to recreate problem:

1) Create new web service and add a reference to Excel
type library

2) Create single web method as follows:

<WebMethod()> Public Function CreateExcelAndQuit() As
String
Dim oExcel As Excel.Application
Dim oExcelSht As Excel.Worksheet

Try
oExcel = New Excel.Application

oExcel.Workbooks.Add()
oExcelSht = oExcel.ActiveSheet()
oExcelSht.Range("A1").FormulaR1C1 = "test"
oExcel.DisplayAlerts = False

oExcelSht.SaveAs("c:\workdocs\testExcel.xls")
oExcel.Quit()


Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)

oExcel = Nothing

Catch ex As Exception
Return "Error : " & ex.Message
End Try
End Function
 
M

Mike Moore [MSFT]

Hi Suzanne,

Excel and Office were designed as client applications, not server
applications. When run in the context of a service, unexpected results can
occur. Please see this article for further information.

257757 INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/?id=257757

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top