Solved

disposing database objects

Posted on 2012-03-27
4
222 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow User To Arrange Columns At Datagridview 3 26
Advice in Xamarin 21 79
SQL LINE CONTINUATION ISSUE 12 33
Help with converting xml file to excel using VB.NET 3 19
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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