-HOME

Google


try to translate this page in english
using google

Electronic
-Lavorare con le EPROM
-Bromografo
-WalPIC
-FMSUSB
-Regolatore di velocità con PIC
-VMixer con PIC

-Caricabatterie NiCd

Programming
-How to correctly free ADOX CatalogClass in C#
-Visual Basic migration tool bug

Modelism
-Zagi12
-Gaggioplano
-Subaru Impreza
-MicroJet

Robocup
-Golemteam Home


Pageloads:
Total 
95171
Last mounth 
4632
Last week 
2019
Last 24h 
41
resetted on 09/01/07




Scrivimi
(Attenzione: inserire la parola NOSPAM nell'oggetto. In caso contrario l'email sarà eliminata automaticamente!)

Write me
(Warning: insert the word NOSPAM in the subject otherwise the email will be automatically erased!)

Last updated
09-Gen-2007

Site statistics by:
http://bbclone.tuxfamily.org/
http://www.countmypage.com/

Subscribe to this sites newsletter to be informed on every project evolution.



Sito realizzato da:
Site realized by:


Walter Zanette

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.

 

He tried with the following code:

 

//create database
ADOX.CatalogClass cat = new ADOX.CatalogClass();
m_sb.Length = 0;
cat.Create(m_sb.AppendFormat(Queries.ConnectionString, m_fqDbFileName).ToString());
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat);


          

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.

 

The final code follows:

 

//create database
ADOX.CatalogClass cat = new ADOX.CatalogClass();
m_sb.Length = 0;
cat.Create(m_sb.AppendFormat(Queries.ConnectionString, m_fqDbFileName).ToString());
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.ActiveConnection);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat);

 

I want to thank Robert Rosati because he envolved me in this little problem.

18-Apr-2006



<<< - by Modellismo Web Ring - >>>



This page was generated in 0.8596 seconds.