Page 1 of 1

OracleConnection.Close()

Posted: Tue 21 Feb 2012 04:00
by sinys
When I write in this stile:

Code: Select all

            using (OracleConnection c = new OracleConnection(connString))
                {

                    c.Open();

                    string commandQuery = @"select lpu.x.y(:pLid, :pRid) from dual";
                    using (OracleCommand cmd = new OracleCommand(commandQuery, c))
                    {
                        cmd.Parameters.Add("pLid", key.lid);
                        cmd.Parameters.Add("pRid", rid);
                        return Convert.ToDecimal(cmd.ExecuteScalar());
                    }
                }
when block "using" ended automatically call c.Close()? or I must write this?

Posted: Tue 21 Feb 2012 13:27
by Pinturiccio
OracleConnection class inherit IDisposable interface, so you can use inside the using block. So c.Close() will be called automatically in the end of the using block.