Solved

disposing database objects

Posted on 2012-03-27
4
219 Views
Last Modified: 2012-03-27
Greetings,



After reading, inserting, deleting items in an Access database using ADO, I always close the connection, but do not dispose of the objects or set any of them to nothing.  I do not seem to have any problems but need some opinions,  (examples if applicable) as to whether or not this is a good practice. I am using vb through vs 2008.

Thanks
0
Comment
Question by:VWhitehead
  • 2
4 Comments
 
LVL 9

Expert Comment

by:armchair_scouse
ID: 37772198
I understand there is something called the 'Garbage Collector' built-in to .Net that disposes of unused objects, but IMHO it is always good programming practice to dispose of unused objects if you have instantiated them.  I believe you can also call the garbage collector directly (GC.Collect?!?) but I would bow to someone with greater knowledge of .Net on that point.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 37772290
It is good practice to get used to disposing of objects as soon as you are finished with them as garbage collection is non-deterministic (meaning it is unknown when it will clean up your unused objects).
The best way to ensure good disposal is the use of the using statement as the object is automatically disposed of at the end using.

Using cn as New SqlConnection(myConnectionString)
   ----
   ----
End Using
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37772305
0
 

Author Closing Comment

by:VWhitehead
ID: 37772490
thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now