如何在.NET中关闭OracleConnection
发布时间:2020-12-12 15:13:14 所属栏目:百科 来源:网络整理
导读:说我有这两个对象: OracleConnection connection = new OracleConnection(connectionString); OracleCommand command = new OracleCommand(sql,connection); 要关闭连接或Oracle,我必须调用command.Dispose(),connection.Dispose()或两者? 这够好吗 using(
说我有这两个对象:
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,并且如果你创建它,然后把它放在一个使用块. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |