1

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)) { .... } ?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
kseen
  • 359
  • 8
  • 56
  • 104

2 Answers2

3

No, it will call Dipose(). A using block will implicitly call Dispose() on the object specified in the using statement.

But often times for a database connection, Dispose() handles the Close() functionality, releasing the connection/processId that keeps a connection.

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.

Bryan Crosby
  • 6,486
  • 3
  • 36
  • 55