说我有这两个对象:
OracleConnection connection = new OracleConnection(connectionString); OracleCommand command = new OracleCommand(sql,connection);
要关闭连接或Oracle,我必须调用command.Dispose(),connection.Dispose()或两者?
这够好吗
using(connection) { OracleDataReader reader = cmd.ExecuteReader(); // whatever... }
using (OracleConnection connection = new OracleConnection(connectionString)) { using (OracleCommand command = new OracleCommand(sql,connection)) { using (OracleDataReader reader = cmd.ExecuteReader()) { } } }
如果它实现了IDisposable,并且如果你创建它,然后把它放在一个使用块.