I need help.....

Hi everybody,

I have this problem where when I instantiate an interop COM object I can't destroy it until my program exits....In this case the COM object is an instance of the Access.Application object (Access 97) as found in the Microsoft Access 8.0 Object Library....here's what i'm doing.

Imports
System.IO
Imports System.Runtime.InteropServices
PublicClass Access97Routines
PublicSharedSub RepairCorruptDatabase(ByRef corruptDBAs FileInfo,ByVal destinationFileNameAsString)
Dim accessAppAsNew Access.Application 'we're talking about access 97
accessApp.DBEngine.CompactDatabase(corruptDB.FullName, destinationFileName)
accessApp.Quit()
Marshal.ReleaseComObject(accessApp)
accessApp =
Nothing
EndSub
End
Class

This problem is that...

accessApp.Quit()
Marshal.ReleaseComObject(accessApp)
accessApp =
Nothing

....doesn't close the access application window. it remains open until I close my app. That's not cool. I need it to close when I'm done with it. Any suggestions are greatly appreciated.

Thanks a lot,

Andeezle

[2485 byte] By [Andeezle] at [2007-12-16]
# 1

Hello,

The ReleaseComObject method doesn't automatically release the reference. Instead, it decrements the reference count. When the reference count is 0, the object is released.

The ReleaseComObject method returns an integer value that represents the current reference count. I suspect you will find that the count is not 0 when you call it only once. In this case, you should probably perform a loop that calls ReleaseComObject until the return value is 0.

Something like the following should work:


accessApp.Quit()

Dim refCount As Integer = -1

While refCount <> 0
refCount = Marshal.ReleaseComObject(accessApp)
End While

accessApp = Nothing


Stephen

StephenMcCloskey at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Stephen,

Marshal.ReleaseComObject(accessApp) returns zero the first time I call. Thanks for your suggestion but it's not working either.

Do you have any more suggestions?

Thanks,

Andy

Andeezle at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
Andy,

I have answered your question on the other thread that you posted:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=59776#59776

Please post only one thread per question.

DavidM.Kean at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified