[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
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.
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 ?
Re: [2005] Shared objects VS Local objects
It's safe but unnecessary.