Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

disposing database objects

Posted on 2012-03-27
4
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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