请看下面的代码:
Private objCommand As SQLCommand
Public Overrides Function ExecuteDataReader(ByVal strCommandType As String, ByVal sqlCommandString As String) As DbDataReader
Dim objDR As SqlDataReader
Try
_objCon = getConnection()
_objCon.Open()
Using _objCon
Using _objCommand
_objCommand.Connection = _objCon
_objCommand.CommandText = sqlCommandString
_objCommand.CommandType = strCommandType
objDR = _objCommand.ExecuteReader
ExecuteDataReader = objDR
End Using
End Using
Catch ex As Exception
Throw
Finally
_objCon = Nothing
_objCommand.Dispose()
_objCommand = Nothing
objDR = Nothing
End Try
End Function
返回关闭,DataReader
因为它在连接对象关闭时关闭。连接对象的寿命如何DataReader
?
我一直在寻找类似的问题,我发现了这个问题:DataReader not closed when Connection is closed,后果?. 但是,它没有回答我的具体问题。