COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook

5

When I run the following code, I get the exception below:

''# NOTE: ExcelApp is a Private main form variable
Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks
Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename)
Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report")

''# Retreive data from sheet

ReleaseCOM(ReportSheet)
ReportBook.Close(True) ''# Error raised here
ReleaseCOM(ReportBook)
ReleaseCOM(ReportBooks)
ERROR:
COMException was unhandled
The object invoked has disconnected from its clients.
(Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

Note: All data appears to have been retreived correctly.

Please help me diagnose and overcome this error.

vb.net
excel
interop
com-interop
excel-interop
asked on Stack Overflow Mar 10, 2010 by Steven • edited Jul 22, 2010 by Todd Main

2 Answers

8

RPC_DISCONNECTED...the dreaded "The object invoked has disconnected from its clients." issue. There are a ton of causes to this, looks like you've covered the global variables issue with Excel.. Can you put the first ReleaseCOM(ReportSheet) below ReportBook(Close) and run it? Also, check out this.

answered on Stack Overflow Mar 10, 2010 by Todd Main • edited May 23, 2017 by Community
-2

I cannot say why it is failing based on the code you are showing.

Have you considered switching from Excel Automation using COM Interop to a 3rd party component?

SpreadsheetGear for .NET will let you load Excel workbooks and get values / get formatted text / recalculate formulas / etc... without the troubles associated with COM Interop.

You can see live ASP.NET samples here and download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

answered on Stack Overflow Mar 10, 2010 by Joe Erickson

User contributions licensed under CC BY-SA 3.0