Neither.
Cn.Close is enough. The important thing is to close the connection, to
release it back into the pool. As soon as the variable goes out of scope,
the GC knows to collect the object. Setting it to Nothing doesn't do
anything, that was something you had to do in VB6.
"NetNut" <(E-Mail Removed)> wrote in message
news:7FF5F715-2614-4FDD-B7C5-(E-Mail Removed)...
> Hello Everyone,
>
> I have received mixed reviews on this question so maybe I can get some
more info.
>
>
> Situation:
>
> You have a ASP.Net application that is highly used and extremely data
cetric. There is a large number of anticipated users and you want to make
sure that all resources are regained as soon as possible.
>
> Which code snipplet is accurate or the best choice for the situation
above:
>
> Dim Cn As SQLClient.SqlConnection = New
SqlCilent.SqlConnection(ConfigurationSettings.AppSettings("SQLConn"))
> CN.Open
>
> Dim Cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("@sp_Test", Cn)
> .
> .
> .
> Answers
> ----------------------------------------------------------------
> A.
> Cn.Close()
> Cmd.Dispose()
> Cn.Dispose()
> Cn = Nothing
> Cmd = Nothing
>
> B.
> Cn.Close()
>
> Cmd.Dispose()
> Cn.Dispose()
>
> With GC
> .SuppressFinialize(Cmd)
> .SuppressFinialize(Cn)
>
> .Collect()
> End With
>
> C.
> Cn.Close
>
> Cn = Nothing
> Cmd = Nothing
>
> --------------------------------------------------------------------------
------
> Please feel free to add something if you have any better techniques
>
|