title: Randomly getting ORA-08177 with only one active session
body: <p>I'm running a program that creates a table and then inserts some data.<br>
  This is the only program that accesses the database.<br>
  I'm getting ORA-08177 randomly.<br>
  Actual code is somewhat complex, but I've written a simple program that reproduces this behavior.  </p>
  
  <pre><code>using System;
  using System.Data;
  using Oracle.DataAccess.Client;
  
  namespace orabug
  {
    class Program
    {
      private const string ConnectionString = ""; // Valid connection string here
  
      // Recreates the table
      private static void Recreate()
      {
        using (var connection = new OracleConnection(ConnectionString)) {
          connection.Open();
          using (var command = connection.CreateCommand()) {
            command.CommandText = @"
              declare
                table_count binary_integer;
              begin
                select count(*) into table_count from sys.user_tables where table_name = 'TESTTABLE';
                if table_count &gt; 0 then
                  execute immediate 'drop table TestTable purge';
                end if;
                execute immediate 'create table TestTable(id nvarchar2(32) primary key)';
              end;";
            command.ExecuteNonQuery();
          }
          connection.Close();
        }
      }
  
      // Opens session sessionCount times, inserts insertCount rows in each session.
      private static void Insert(int sessionCount, int insertCount)
      {
        for (int sessionNumber = 0; sessionNumber &lt; sessionCount; sessionNumber++)
          using (var connection = new OracleConnection(ConnectionString)) {
            connection.Open();
            using (var transaction = connection.BeginTransaction(IsolationLevel.Serializable)) {
              for (int insertNumber = 0; insertNumber &lt; insertCount; insertNumber++)
                using (var command = connection.CreateCommand()) {
                  command.BindByName = true;
                  command.CommandText = "insert into TestTable (id) values(:id)";
                  var id = Guid.NewGuid().ToString("N");
                  var parameter = new OracleParameter("id", OracleDbType.NVarchar2) {Value = id};
                  command.Parameters.Add(parameter);
                  command.Transaction = transaction;
                  command.ExecuteNonQuery();
                }
              transaction.Commit();
            }
            connection.Close();
          }
      }
  
      static void Main(string[] args)
      {
        int iteration = 0;
        while (true) {
          Console.WriteLine("Running iteration: {0}", iteration);
          try {
            Recreate();
            Insert(10, 100);
            Console.WriteLine("No error");
          }
          catch (Exception exception) {
            Console.WriteLine(exception.Message);
          }
          iteration++;
        }
      }
    }
  }
  </code></pre>
  
  <p>This code runs infinite cycle.<br>
  On each iteration it performs the following actions 10 times:</p>
  
  <ul>
  <li><p>Open session</p></li>
  <li><p>Insert 100 rows with random data</p></li>
  <li><p>Close session</p></li>
  <li><p>Displays a message saying that no error occured</p></li>
  </ul>
  
  <p>If error occurs, the exception is caught and its message is printed and
  then the next iteration is executed.  </p>
  
  <p>Here is sample output.  As you can see ORA-08177 is interleaving with successful interations randomly.  </p>
  
  <pre><code>Running iteration: 1
  No error
  Running iteration: 2
  ORA-08177: can't serialize access for this transaction
  Running iteration: 3
  ORA-08177: can't serialize access for this transaction
  Running iteration: 4
  ORA-08177: can't serialize access for this transaction
  Running iteration: 5
  ORA-08177: can't serialize access for this transaction
  Running iteration: 6
  ORA-08177: can't serialize access for this transaction
  Running iteration: 7
  No error
  Running iteration: 8
  No error
  Running iteration: 9
  ORA-08177: can't serialize access for this transaction
  Running iteration: 10
  ORA-08177: can't serialize access for this transaction
  Running iteration: 11
  ORA-08177: can't serialize access for this transaction
  Running iteration: 12
  ORA-08177: can't serialize access for this transaction
  Running iteration: 13
  ORA-08177: can't serialize access for this transaction
  Running iteration: 14
  ORA-08177: can't serialize access for this transaction
  Running iteration: 15
  ORA-08177: can't serialize access for this transaction
  Running iteration: 16
  ORA-08177: can't serialize access for this transaction
  Running iteration: 17
  No error
  Running iteration: 18
  No error
  Running iteration: 19
  ORA-08177: can't serialize access for this transaction
  Running iteration: 20
  No error
  </code></pre>
  
  <p>I'm running Oracle 11.1.0.6.0 and using ODP.NET 2.111.6.20.<br>
  Changing isolation level to <code>ReadCommited</code> fixes the problem, but I really want to run this at <code>Serializable</code> level.<br>
  Looks like <a href="https://stackoverflow.com/questions/785765/ora-08177-cant-serialize-access-for-this-transaction">I'm not alone</a>
  with this problem, but answer was not given, so I'm asking again.<br>
  What am I doing wrong and how could I fix this?  </p>
  
  <p><strong>edit by APC</strong></p>
  
  <p>To prevent anybody else barking up the wrong tree, the posted code sample is just a generator of ORA-8177 errors.  Apparently the actual code is different; specifically, the dropping and recreating of tables is a red herring.    </p>