471,318 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Using ADOX with C#.

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.ConnectionStr ing);

//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
Jan 6 '06 #1
4 10528
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?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.com> wrote in message
news:e5*************@TK2MSFTNGP14.phx.gbl...
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.ConnectionStr ing);

//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

Jan 6 '06 #2
Nicholas Paldino [.NET/C# MVP] wrote:
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.

Jan 6 '06 #3
Frank,

Yes, you are releasing the connection, but that is not the only COM
object there is. There is also the catalog object.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
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.


Jan 6 '06 #4
Nicholas Paldino [.NET/C# MVP] wrote:
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.ConnectionStr ing);

//do the work
....

//close the connection
((ADODB.Connection) connection.ActiveConnection).Close();
Marshal.ReleaseComObject(connection);
Jan 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Developer98115 | last post: by
2 posts views Thread by Gandalf | last post: by
6 posts views Thread by Claudia Fong | last post: by
3 posts views Thread by Miro | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.