|

-HOME

try to translate this page in english
using google
Electronic
-PIC18F1XK50 programmer
-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
Tools
-PortRedirector
Modelism
-Zagi12
-Gaggioplano
-Subaru
Impreza
-MicroJet
Robocup
-Golemteam
Home

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
10-Oct-2009
Site statistics by:
http://bbclone.tuxfamily.org/
http://www.countmypage.com/
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
|