Dot-Net
是否結束使用關閉打開的 SQL 連接
如果我將 SQLConnection 包裝在 Using 中,我應該關閉它還是使用結束處理它?
using cn as new system.data.sqlclient.sqlconnection() cn.open '{do a bunch of other stuff with commands and datareaders here} cn.close 'Do I need this? end using
在有問題的對象(在您的範例中)上退出 using 塊呼叫 .Dispose()
cn,對於 SqlConnection 將關閉連接和任何打開的資源。