1

我得到了这个代码:

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是用于 Oracle 的 devArt dotConnect 类。这段代码c.Close()用完时会调用(OracleConnection c = new OracleConnection(globalDict[byAlias(connAlias)].connString)) { .... }吗?

4

2 回答 2

3

不,它会调用Dipose(). 块将using隐式调用语句中Dispose()指定的对象。using

但通常对于数据库连接,Dispose()处理Close()功能,释放保持连接的连接/processId。

于 2012-02-21T05:28:43.753 回答
0

I would also like to add that in the event of an exception somewhere in your //here working on oraclecommand (basically inside your using(...){ } 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 to Close() after your using 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.

于 2012-02-21T06:59:08.090 回答