我以前使用的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