Using ADOX with C#.

F

Frank Rizzo

I am using ADOX to make changes to an Access database that would be
difficult to do via the System.Data.OLEDBClient. So far I have no
trouble actually doing the work, however, I have trouble closing the
connection to the Access database.

//open connection
ADOX.CatalogClass connection = new ADOX.CatalogClass();
connection.let_ActiveConnection(this.ConnectionString);

//do the work
....

//close the connection
((ADODB.Connection) connection.ActiveConnection).Close();
Marshal.ReleaseComObject(connection);

Even though the code to close the connection does cause an error, it
doesn't actually close the connection, because if I try to connect to
the database later, it errors out saying that it is exclusively locked.

How do I actually close the connection created via ADOX?

Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

Frank,

Just off the top of my head, do you have connection pooling turned on?
Perhaps this has something to do with it.

Also, did you dispose of the catalog class properly?
 
F

Frank Rizzo

Nicholas said:
Frank,

Just off the top of my head, do you have connection pooling turned on?
Perhaps this has something to do with it.

Also, did you dispose of the catalog class properly?

Well, I guess that's the crux of the matter. How does one dispose of it
properly?

I thought

Marshal.ReleaseComObject(connection);

will do the trick.
 
N

Nicholas Paldino [.NET/C# MVP]

Frank,

Yes, you are releasing the connection, but that is not the only COM
object there is. There is also the catalog object.
 
F

Frank Rizzo

Nicholas said:
Frank,

Yes, you are releasing the connection, but that is not the only COM
object there is. There is also the catalog object.

Connection is the catalog object. Consider the code:

//open connection
ADOX.CatalogClass connection = new ADOX.CatalogClass();
connection.let_ActiveConnection(this.ConnectionString);

//do the work
....

//close the connection
((ADODB.Connection) connection.ActiveConnection).Close();
Marshal.ReleaseComObject(connection);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top