P
Paul
Hi, I think I remember reading somewhere that if you use a With block as
below, then the call to Dispose in the Finally block is completely
redundant because Dispose will be called by the system when the End With
is reached. Can anyone confirm this, or otherwise?
With New SqlCommand()
Try
.CommandType = CommandType.StoredProcedure
.CommandText = "dbo.uspCRChangeRequestInsert"
'Irrelevant code missing here...
.Connection = Conn
Conn.Open()
.ExecuteScalar()
Catch Ex As Exception
'Handle error
Finally
.Dispose() 'Is this line completely redundant??
Conn.Dispose()
End Try
End With
(Now I know that Dispose is never strictly required for managed
components, but we call it to ensure all connections are returned to the
pool as quickly as possible.)
Thanks,
Paul
below, then the call to Dispose in the Finally block is completely
redundant because Dispose will be called by the system when the End With
is reached. Can anyone confirm this, or otherwise?
With New SqlCommand()
Try
.CommandType = CommandType.StoredProcedure
.CommandText = "dbo.uspCRChangeRequestInsert"
'Irrelevant code missing here...
.Connection = Conn
Conn.Open()
.ExecuteScalar()
Catch Ex As Exception
'Handle error
Finally
.Dispose() 'Is this line completely redundant??
Conn.Dispose()
End Try
End With
(Now I know that Dispose is never strictly required for managed
components, but we call it to ensure all connections are returned to the
pool as quickly as possible.)
Thanks,
Paul