这里调用的是 Close on 数据库连接吗?
我得到了这个代码:
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) { }
I got this code:
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 is class of devArt dotConnect for Oracle.
Will this code call c.Close()
when it goes out of (OracleConnection c = new OracleConnection(globalDict[byAlias(connAlias)].connString)) { .... }
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它会调用
Dipose()
。using
块将在using
语句中指定的对象上隐式调用Dispose()
。但通常情况下,对于数据库连接,
Dispose()
会处理Close()
功能,释放保持连接的连接/processId。No, it will call
Dipose()
. Ausing
block will implicitly callDispose()
on the object specified in theusing
statement.But often times for a database connection,
Dispose()
handles theClose()
functionality, releasing the connection/processId that keeps a connection.我还想补充一点,如果您的
//here 处理 oraclecommand
中的某处出现异常(基本上在您的using(...){ }
语句中, 。根据设计,您应该能够对实现 IDisposable 的对象进行多次调用,从而发出调用
Close()
之后using
代码块不会执行任何操作,因为连接已关闭/已返回到池中,对象清理后的任何其他调用都应该返回并执行操作。没有什么。I would also like to add that in the event of an exception somewhere in your
//here working on oraclecommand
(basically inside yourusing(...){ }
statement,Dispose()
will also be called.By design, you should be able to make multiple to calls to an object implementing
IDisposable
. In your case, issuing a calling a call toClose()
after yourusing
block of code will simply do nothing, as the connection has already closed/been returned to the pool. Any additional calls after the object has cleaned up should just return and do nothing.