According to the MSDN documentation for the OracleClient.OracleCommand:
Public Sub ReadMyData(ByVal connectionString As String)
Dim queryString As String = "SELECT EmpNo, DeptNo FROM Scott.Emp"
Using connection As New OracleConnection(connectionString)
Dim command As New OracleCommand(queryString, connection)
connection.Open()
Dim reader As OracleDataReader = command.ExecuteReader()
Try
While reader.Read()
Console.WriteLine(reader.GetInt32(0) & ", " _
& reader.GetInt32(1))
End While
Finally
' always call Close when done reading.
reader.Close()
End Try
End Using
End Sub
The OracleCommand is not wrapped in a Using block.
Question: Should it be? OracleCommand inherits from DbCommand, which implements IDisposable.
I'm looking at code that does the following, and we're having problems with implicit cursors not getting closed:
Dim cmd As OracleCommand = createCommand("some sql")
ds = GetDataSet(cmd)
cmd.Dispose()
cmd = Nothing
GetDataSet looks like:
Dim da As New OracleDataAdapter()
Dim ds As New DataSet()
Using conn As OracleConnection = GetOpenConnection()
cmd.Connection = conn
da.SelectCommand = cmd
da.Fill(ds, 0)
cmd.Connection = Nothing
End Using
da.Dispose()
da = Nothing
Return ds
Is this going to leak resources?