[英]Is Close on database connection calling here?
我得到了这段代码:
try
{
using (OracleConnection c = new OracleConnection(globalDict[byAlias(connAlias)].connString))
{
c.Open();
using (OracleCommand recordExistentQuery = new OracleCommand("regular.IsExistent", c))
{
// here working on oraclecommand
}
}
} catch(Exception exc) { }
OracleConnection是devArt dotConnect for Oracle的类。 这个代码在它离开时会调用c.Close()
(OracleConnection c = new OracleConnection(globalDict[byAlias(connAlias)].connString)) { .... }
?
不,它将调用Dipose()
。 using
块将对using
语句中指定的对象隐式调用Dispose()
。
但通常情况下,对于数据库连接, Dispose()
处理Close()
功能,释放保持连接的连接/ processId。
我还想补充一点,如果在//here working on oraclecommand
(基本上在你的using(...){ }
语句中的某个地方发生异常,也会调用Dispose()
。
按照设计,您应该可以对实现IDisposable
的对象进行多次调用。 在您的情况下,在using
代码块之后发出调用Close()
的调用将无法执行任何操作,因为连接已关闭/已返回到池中。 在对象清理完之后的任何其他调用应该只返回并且什么都不做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.