closing an OleDB database connection

Hi guys!
I am just confused which to use in
closing an OleDB database connection
I read about connection.dispose and stuff
but right now I am doing this
Try
connection.Open
Catch
Finally
If connection.State = ConnectionState.Open Then
connection.Close()
connection= Nothing
End If


Is this Ok I read about dispose and I am confused when to use it...
Please enlighten me...Thanks!



Answer this question

closing an OleDB database connection

  • sel

    Hi,

    Yes. That would do.




    cheers,

    Paul June A. Domag


  • Bohdan

    Hi,

    In .Net you cannot explicitly destroy an object. All you can do is mark it as "ready for disposal" so that when the GC (Garbage Collector) runs it would clean the object from the memory. You use the dispose method to mark the object as already disposed. Your code is quite fine, but I suggest commenting out the setting to nothing part and replace it with a dispose() call to the connection...




    cheers,

    Paul June A. Domag


  • Pater_Peter

    Thanks for your reply.
    So I instead of connection = Nothing I should just write connection.Dispose, right

  • closing an OleDB database connection