Solved

disposing database objects

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 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

24 Experts available now in Live!

Get 1:1 Help Now