473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 10709
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Developer98115 | last post by:
I need help getting schema information from an existing SQL Server database. My thought was that you could use ADOX via InterOp. Has anyone done this successfully and how? I have created a...
2
by: Gandalf | last post by:
I'm creating relationships between tables using VBA and ADOX. I can create one-to-one relationships with an inner join, but I can't figure out how to create these relationships with an outer join...
6
by: Claudia Fong | last post by:
Hello, I'm using the sql statement below to create a new table from an old one. But I found a little problem with that. In my old table DEP2004, I have one field's property allow zero length...
2
by: Randy | last post by:
I am trying to relink some Oracle tables in an Access database via VB.NET and ADOX. I receive the following error when executing the cat.ActiveConnection link "Arguments are of the wrong type,...
2
by: Tim Frawley | last post by:
I am attempting to change the ODBC Link Provider String in an Access database linked to an Oracle server using ADOX in VB.NET. I created some code using the example from post:...
3
by: gaffar | last post by:
Sir, Using ADOX I am developing an application in vb.net and the backend database is ms-access. i have created ms-access databse and tables and assigned primary keys to the tables through the...
2
by: genojoe | last post by:
Using ADOX to update a Property does not work. I want to change the Access database for a linked table. My abridged code is: Dim oCAT As ADOX.Catalog oCAT = New ADOX.Catalog...
1
by: sunlight_sg | last post by:
Hello, i am using ADOX + VB .NET to create a Access Database programmatically. I plan to set some properties of the column such primary key. The code is as follows: Dim cat As ADOX.Catalog...
1
by: Hexman | last post by:
I'm creating a new Access table using ADOX. I can add columns and indexes, but I'm baffled on how to change field properties. Can someone give me a hand? Want to change properties such as:...
3
by: Miro | last post by:
Something weird I have run into when trying to add a boolean field to an Access table by code. -Just wondering if anyone else has run into this. ( vb.net 2005 express ) If I add any other...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.