2

私は、try / catch/finallyブロックを使用して開いているデータリーダーを閉じていました。

 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を実行しますか?

4

2 に答える 2

7

オブジェクトは破棄されます。はい、これでDataReaderが閉じます。

于 2010-08-27T17:07:45.267 に答える
0

リーダーは閉じられますが、データベース接続のアンダーレイにはADO.NET接続プールで管理されるため、これは必要ありません。詳細については、この回答を確認してください:C#MySqlConnectionは閉じません

于 2014-04-23T12:40:04.090 に答える