Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classic ADO and VB.NET - dispose?

Status
Not open for further replies.

mhectorgato

Programmer
Jul 12, 2005
5
US
My VB.NET application uses ADO 2.x to connect to a SQL2000 database. It uses a static recordset to read/write data in a random access mode - using the AbsolutePosition property to navigate forward and backwards through the recordset.

Since I'm not using ADO.NET, I assume that this using unmanaged resources. However, I don't see any way to dispose those objects.

How do I properly clean up these objects - connection and recordset?

Do I just set them to nothing after closing them?

Thanks for the help
 
mhectorgato said:
My VB.NET application uses ADO 2.x to connect to a SQL2000 database

I have to ask, why?

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
My understanding of ADO.NET is that is either supports disconnected recordsets or connected forward only.

This is server application which hands out information to various clients. The data is processed and returned to the server in an asynchronous fashion. When client sends back the data, I have to update the original table with the result.

The data for these "jobs" can range in size from 5 records upto several million records.

 
I would recommend switching to ADO.Net as well. ADO.Net supports disconnect recordsets (data tables and XML) and forward only connections, but it also has an excellent direct connect mode. It took me a bit to warm up to the ADO.Net beast, and there are still parts I don't like, but it integrates so well into so many controls and the data table is such an awesome tool.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
excellent direct connect mode"

This allows forward and backwards movements and updating?

Where can I find info on this?
 
Take a look at the book: "Database Programming with Visual Basic .Net" by Carsten Thomsen, from Apress. It contains a wealth of info on ADO.net.
 
I'll take a look. I'm sure it will take some considerable re-engineering, as I'm using ADO fairly extensively in my app. I do use ADO.NET in other programs, just from what I knew about ADO.NET it didn't seem like a good fit.

In the meantime, does anyone have an answer to my orignal question?

 
Is it not simply...

rs.Close
rs = nothing

cn.Close
cn = nothing


Maybe I'm missing something here.

Dale
 
When anything goes out of scope it should get picked up by the garbage collector. So other then closing them, you don't >Need< to do anything. The Garbage collector can be kind of retarded and slow though. So setting an object = nothing is a good idea. setting an object = nothing will fire the .dispose event. so calling .dispose isn't going to be anything special over setting it = nothing. If the GC is still being retarded, you can call GC.Collect for force it to clean up the memory.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Dale and Rick

That's what I assume as well. I do close both objects and set them to nothing.

I wasn't sure, based on the fact that classic ADO is unmanaged, that the GC would behave in the desired manner. I've read articles on sites (which I can't find now) that this unmanaged objects many not be cleanup properly, which can lead to memory problems and possibly causing apps to crash.

I'm getting "Out of memory" and "Memory error" errors. So, I wanted to make sure that my ADO objects are being disposed of properly.

I do periodically call the GC manually.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top