Compacting an Access 97 DB from VB.NET 2003

Hi everybody,

Here's my code,

Imports System.IO
Public Class Access97Routines

Public Shared Sub RepairCorruptDatabase(ByRef corruptDB As FileInfo, ByVal destinationFileName As String)
Dim accessApp As New Access.Application
Try
accessApp.DBEngine.CompactDatabase(corruptDB.FullName, destinationFileName)
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical, App.Title)
Finally
accessApp.Quit()
End Try
End Sub

End Class

Me problem be that the Access application remains open no matter what, even if I set the accessApp var = nothing. But when I close my app then the Access app that I instantiated is destroyed and goes away.

I thought of explicitly destroying the access app while I have a reference to it but I don't know if you can do that or how to do it. And the Access.Application object doesn't support the .Dispose method because it is an interop assembly.

Could someone please help and point me in the right direction?

Thanks a lot.

Andeezle

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

As Access.Application will be a COM reference, you will need to call Marshall.ReleaseComObject(Object) after your call to accessApp.Quit().

DavidM.Kean at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
help me that didn't work please

-andeezle

Andeezle at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
I was too hasty. Unfortunately, the Access.Application window is still open and visible and still will not go away until my program exits. Any other ideas or suggestions?

I tried your suggestion as follows but it's not working:

Imports System.IO
Imports System.Runtime.InteropServices
Public Class Access97Routines
Public Shared Sub RepairCorruptDatabase(ByRef corruptDB As FileInfo, ByVal destinationFileName As String)
Dim accessApp As New Access.Application
Try
accessApp.DBEngine.CompactDatabase(corruptDB.FullName, destinationFileName)
C
atch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical, App.Title)
Finally
accessApp.Quit()
Marshal.ReleaseComObject(accessApp)
End Try
End Sub
End
Class

Thanks a lot,

Andeezle

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

unbelievable....unbelievable


-andeezle

p.s. u hope someone can stop this spam ***. we never had this problem at windowsforms.net . the mederators might have seen spam, but at least we user's didn't have to waste our time sifting through this GD spam ***.

Andeezle at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
Andeezle, my interpretation on your previous post is that David's suggestion actually worked. Let me know if that aint so.

Kit
kitg@microsoft.com

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

I'm not entirely sure what your comments above are referring to, however I just tried your code above and found that you also had to release the DBEngine reference, ie:


Dim engine As DAO._DBEngine = accessApp.DBEngine

DBEngine.CompactDatabase(corruptDB.FullName, destinationFileName)

Marshal.ReleaseComObject(engine)

David

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

I wish it were so Kit but it seems that it didn't work ( david's post ). So far I haven't solved the problem. Any advice is greatly appreciated.

Thanks,

Andy

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

Have you tried the latest code in my previous post above?

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

Yes. Releasing DBEngine worked like a charm. Thank you very much and sorry for posting so many times, i was panicking.

Thanks again,

Andy

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

regarding my comments about spam, a spam post made its way into my thread but a moderator must of trashed it after i made my comments about spam. my post is little confusing now since the spam post as been removed. LOL.

-Andy

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

.NET Development

Site Classified