我以前使用的try/catch關閉打開的DataReader/finally塊:.NET MySql沒有「使用」關閉數據讀取器?
Dim dr As MySqlDataReader = Nothing
Try
dr = DBConnection.callReadingStoredProcedure("my_sp")
Catch ex As Exception
' the caller will handle this
Throw ex
Finally
If dr IsNot Nothing Then dr.Close()
End Try
但我認爲它應該是清潔劑(和稍快)使用「使用」 VB關鍵字:
Using dr As MySqlDataReader = DBConnection.callReadingStoredProcedure("my_sp")
End Using
' dr is surely disposed, but is it closed?
IDispose接口(由Using使用)是否在DataReader上執行Close?
我相信它是繼承IDataReader繼承IDisposable。我相當肯定這是微軟將執行的行爲。 – IAbstract 2011-05-19 23:52:58