Suppose I do the following:
using (OracleConnection conn = new OracleConnection(connStr))
{
OracleTransaction trans = conn.BeginTransaction();
OracleCommand command = new OracleCommand(cmdTxt, conn, trans);
command.ExecuteNonQuery();
}
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.
source
share