.NET mySQL可以“使用”关闭数据标准?
-
01-10-2019 - |
题
我曾经使用try/catch/终于封锁开放的数据标准器:
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接口(要求使用)是否在DataReader上执行关闭?
解决方案
物体将被处置。是的,这关闭了数据标准。
其他提示
读者将关闭,但这对于底层数据库连接不是必需的,因为它是使用ADO.NET连接池进行管理的。检查此答案以获取更多信息: C#mysqlConnection不会关闭
不隶属于 StackOverflow