PDA

Click to See Complete Forum and Search --> : Closing connections


msdnexpert
Oct 5th, 2000, 08:21 AM
Which of the following is appropriate for closing an ADO connection or are both equivalent?

1.
MyConnection.close
Set MyConnection=Nothing

2.
Set MyConnection=Nothing

vbuser1976
Oct 5th, 2000, 08:29 AM
No, they are not equivalent. #2 may be okay, you only set the connection back to nothing but you didn't close the connection. Therefore the connection is still active and that might cause problems down the line in the application.

Hope this helps.

sanon
Oct 5th, 2000, 04:03 PM
In my projects, I've never used Myconnection.close before using Set Myconnection = Nothing. However, when I checked back to the server, the connection was terminated. Therefore, I think it doesn't matter whether you close the connection before destroying the object or not. In other words, when you set the object = nothing, it means you destroy it. As a result, everything should be destroyed.

msdnexpert
Oct 5th, 2000, 11:59 PM
Thanks vbuser and sanon. Well I guess a confirmation from the gurus at Microsoft would put to rest all our doubts. Thanks again.