ADO.NET, closing OracleConnection without first committing or rollback: will it leak?

Suppose I do the following:

using (OracleConnection conn = new OracleConnection(connStr))
{
    OracleTransaction trans = conn.BeginTransaction();
    OracleCommand command = new OracleCommand(cmdTxt, conn, trans);
    // this statement is executed in a transaction context:
    command.ExecuteNonQuery();
}
// the using statement will dispose and thus close the connection.
// a rollback is done implicitly

Although I did not complete transaction.Rollback(), my tests showed that rollback is performed implicitly.

My question is: will this code contact leaks or something else?

Edit1: I am a namespace System.Data.OracleClient.

Edit2: This is sample sample code. A more realistic scenario is that an exception occurs inside the using statement, and the statement Commit()has not yet been executed.

Edit3: From the answer, I think this is beneficial:

using (OracleConnection conn = new OracleConnection(connStr))
using (OracleTransaction trans = conn.BeginTransaction())
using (OracleCommand command = new OracleCommand(cmdTxt, conn, trans))
{
    command.ExecuteNonQuery();
    trans.Commit();
}

There must be a clear order of something and it is clear what is happening.

+3
source share
1 answer

. using , OracleConnection , , , .

OracleTransaction IDisposable, , use , .

using (OracleTransaction trans = conn.BeginTransaction())
{
  // ...
  trans.Commit();
}

, ; , , .

, , using OracleCommand, .

+2

Source: https://habr.com/ru/post/1706803/