J
Juxx
Hi All,
I've a big doubt about reference to object destruction.
In the test below I call 2 times a sub passing a datareader in 2
different ways.
Who can tell me if datareader is destroyed in both cases and
so connection closed (using dr behavior)?
*-*-*-*
Case 1
*-*-*-*
Dim cm As SqlCommand
Dim dr As SqlDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
' Datareader is passed ByVal to MySub
' I have to close "dr" here and "otherdr" in MySub
MySub(dr)
dr.Close()
dr = Nothing
*-*-*-*
Case 2
*-*-*-*
Dim cm As SqlCommand
' No reference to datareader exist (?) at this level,
' I have only to close "otherdr" in MySub ?
MySub(cm.ExecuteReader(CommandBehavior.CloseConnection))
*-*-*-*
MySub
*-*-*-*
Sub MySub(ByVal otherdr As SqlDataReader)
While otherdr.Read
' Do something
End While
otherdr.Close()
otherdr = Nothing
End Sub
I've a big doubt about reference to object destruction.
In the test below I call 2 times a sub passing a datareader in 2
different ways.
Who can tell me if datareader is destroyed in both cases and
so connection closed (using dr behavior)?
*-*-*-*
Case 1
*-*-*-*
Dim cm As SqlCommand
Dim dr As SqlDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
' Datareader is passed ByVal to MySub
' I have to close "dr" here and "otherdr" in MySub
MySub(dr)
dr.Close()
dr = Nothing
*-*-*-*
Case 2
*-*-*-*
Dim cm As SqlCommand
' No reference to datareader exist (?) at this level,
' I have only to close "otherdr" in MySub ?
MySub(cm.ExecuteReader(CommandBehavior.CloseConnection))
*-*-*-*
MySub
*-*-*-*
Sub MySub(ByVal otherdr As SqlDataReader)
While otherdr.Read
' Do something
End While
otherdr.Close()
otherdr = Nothing
End Sub