|
-
Dec 7th, 2007, 04:35 AM
#1
Thread Starter
Addicted Member
[2005] Shared objects VS Local objects
I have these variable:
vb Code:
Public Shared SQLConn As SqlClient.SqlConnection
It use for doing ADO.NET connection. So, after I finished database processing, I close and re-use that variable. Is it wise? Which are better than I use this on every ADO.NET transaction?
vb Code:
Using MyConn As New SqlClient.SqlConnection
'DB processing here
End Using
Since I heard that Garbage Collector won't remove an object immediately, I thought an idea about using a single object repeatedly than create and dispose an object each processing.
Regards,
Michael
Last edited by michaelrawi; Dec 7th, 2007 at 04:37 AM.
Reason: Add the VB code tag
-
Dec 7th, 2007, 04:50 AM
#2
Re: [2005] Shared objects VS Local objects
Declaring a connection at the class level is fine, but there's no reason for the variable to be Shared.
-
Dec 7th, 2007, 05:21 AM
#3
Thread Starter
Addicted Member
Re: [2005] Shared objects VS Local objects
What I want is to use the object in DB processing in other class as well. That's why I declare it on shared level.
Is it safe / wise ?
-
Dec 7th, 2007, 05:39 AM
#4
Re: [2005] Shared objects VS Local objects
It's safe but unnecessary.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|