gpt4 book ai didi

mysql - .NET MySql "Using"关闭数据读取器?

转载 作者:行者123 更新时间:2023-11-29 01:19:04 25 4
gpt4 key购买 nike

我曾经使用 try/catch/finally block 关闭打开的数据读取器:

 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 接口(interface)(Using 需要)是否对 DataReader 执行关闭操作?

最佳答案

对象将被释放。是的,这将关闭 DataReader。

关于mysql - .NET MySql "Using"关闭数据读取器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3586513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com