当我从我的 C# 代码查询数据库时,我通常使用类似这样的结构:
using (var connection = new OleDbConnection(connStr))
using (var command = new OleDbCommand(query, connection))
using (var adapter = new OleDbDataAdapter(command))
{///}
我应该实际使用所有这些“使用”,还是仅处理连接就足够了,所有相关对象也将被处理?
最佳答案
it will be enough to dispose only connection and all related objects will be disposed too?
没有。处置连接只会处置连接对象。
通常,释放每个实现了 IDisposable
的对象是一种安全的做法。 (还有一点,处理 Command
对象不会处理相关的连接对象)
关于c# - 配置连接、命令、适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28857813/