Se vi piace il mio sito e volete fare una donazione:
If you like my website and you want to make a donation:
How to correctly free ADOX CatalogClass
A few days ago a friends of mine was fighting against Visual Studio 2005 trying to correctly free an ADOX CatalogClass instance that he was using to create a copy of a database to perform a "compact database" action. Since ADOX is an unmanaged object he found that the right way to free this unmanaged resource was through a System.Runtime.InteropServices.Marshal.FinalReleaseComObject() call.
The problem was that after the FinalReleaseComObject call the cat instance was disconnected from the unmanaged object, but it was still living and connected with the database. We tried a little to find the reason of this problem, and finally we have found that before releasing the catalogueclass instance it's necessary to release the connection to the database that is contained in it's ActiveConnection property. Doing so the unmanaged object closes it's connection to the database freeing the file, and than with a second call to FinalReleaseComObject we can release the object.