title: Performing an Oracle Transaction using C# and ODP.NET
body: <p>I'm confused. On the face of it, performing a transaction in C# seems
  simple. From here:</p>
  
  <p><a href="http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleTransactionClass.htm" rel="noreferrer">http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleTransactionClass.htm</a></p>
  
  <pre><code>string constr = "User Id=scott;Password=tiger;Data Source=oracle";
  OracleConnection con = new OracleConnection(constr);
  con.Open();
  
  OracleCommand cmd = con.CreateCommand();
  cmd.CommandText = "SELECT COUNT(*) FROM MyTable";
  
  // Start a transaction
  OracleTransaction txn = con.BeginTransaction(
    IsolationLevel.ReadCommitted);
  
  try
  {
    // Insert the same row twice into MyTable
    cmd.CommandText = "INSERT INTO MyTable VALUES (1)";
    cmd.ExecuteNonQuery();
    cmd.ExecuteNonQuery(); // This may throw an exception
    txn.Commit();
  }....
  </code></pre>
  
  <p>So, create a connection, begin a transaction on that connection, and then off you go until you want to commit or rollback.</p>
  
  <p>However, other sources, such as here:</p>
  
  <p><a href="https://forums.oracle.com/thread/319121" rel="noreferrer">https://forums.oracle.com/thread/319121</a></p>
  
  <p>advocate setting the Transaction property of the OracleCommand object itself. e.g.</p>
  
  <pre><code>cmd.Transaction = txn;
  </code></pre>
  
  <p>Yet other sources say that this property is read only. It's not actually read
  only, but nowhere appears to clearly say what it does.</p>
  
  <p>My confusion, therefore, is that the existence of the Transaction
  property on the OracleCommand object seems to suggest that it should
  be used to perform that command as part of a transaction, and yet
  Oracle's own documentation does not use this property. So what is it
  for?</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>do I need to set the Transaction property of my OracleCommand, and
  if so, what exactly does this do?</li>
  <li>If I've started a transaction on a connection, are ALL subsequent
  commands performed on that connection (until a commit or rollback) part of that transaction, even if I don't set the Transaction
  property on those commands?</li>
  </ol>