home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

VB Destruction

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2356
Discussions: 200,940, Posts: 2,379,262, Members: 246,303
Old October 21st, 2002, 08:04 PM   Digg it!   #1 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
VB Destruction

Ok for lack of a better subject line lol
I'm starting a class in VB.net that will manage database methods. I have a few private objects (sqlcommand, sqlconnection etc) and I have an open database connection method below. This method will be called by another public method within the class. Now my question is if I return a sql connection as follows...


Private Function OpenDBConnection() As SqlConnection

OpenDBConnection = New SqlConnection(g_strConnection)

End Function

how do I close the connection?
I can't set OpenDbConnection = Nothing because the function work like that.
I'm still not quite familiar with this part, so bear with me lol

Now the only other way I've thought it could work is instead of returning the sqlconnection, I could create a private object in the class and set that instead?
vass0922 is offline   Reply With Quote
Old October 21st, 2002, 08:13 PM     #2 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
scratch that, just realized for my purposes its better to construct with a sqlconnect object for the class....

although still interested in the answer
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is offline   Reply With Quote
Old October 22nd, 2002, 08:58 AM     #3 (permalink)
Member
 
Join Date: Oct 2001
Location: Midland, NC USA
Posts: 64
You would probably want to have a Close method for the class that passes the Close command on through to your base Connection object.

In the .NET framework, all objects are (supposedly) garbage collected automagically when they are no longer referenced and the memory is needed by something else. You no longer have direct control over when they are ultimately destroyed. The .NET framework and the OS are much more facile than mere mortals at handling things like that. heh
UncaDanno is offline   Reply With Quote
Old October 23rd, 2002, 07:40 PM     #4 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
supposedly being the key word
I'm still gonna close everything "manually" to make sure things are opened and closed correctly.

Thanks
vass0922 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2910)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (43)
Obama the Muslim (14)
Regular Build (5)
Is the PSU I received dead? (11)
windows vista security holes (9)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
Open With ..... Win7 (0)
Regular Build (5)
java code for fibonacci (1)
screen resolution vs monitor size (0)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
Wireless Televisions. (8)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Wireless Router+Cable Modems and Much.. (0)


All times are GMT -4. The time now is 01:27 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28