.NET MySql执行“使用”会关闭datareader吗?

时间:2010-08-27 17:02:14

标签: mysql vb.net mysqldatareader

我曾经使用try / catch / finally块关闭一个打开的datareader:

 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

但我认为使用“Using”VB关键字应该更干净(并且更快):

Using dr As MySqlDataReader = DBConnection.callReadingStoredProcedure("my_sp")

End Using
'   dr is surely disposed, but is it closed? 

IDispose接口(使用时需要)是否在DataReader上执行Close?

2 个答案:

答案 0 :(得分:7)

该物件将被处置。是的,这会关闭DataReader。

答案 1 :(得分:0)

Reader将被关闭,但这不是必需的,因为它是使用ADO.NET连接池管理的。 请查看此答案以获取更多信息:C# MySqlConnection won't close