日期:2014-05-20  浏览次数:20763 次

oralce 事务处理,调用这个方法,程序就死了。急。。
public void RunOracleTransaction(string myConnString)
  {
  OracleConnection myConnection = new OracleConnection(myConnString);
  myConnection.Open();

  OracleCommand myCommand = myConnection.CreateCommand();
  OracleTransaction myTrans;

  // Start a local transaction
  myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted);
  // Assign transaction object for a pending local transaction
  myCommand.Transaction = myTrans;

  // try
  //{
  myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
  myCommand.ExecuteNonQuery();
  myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')";
  myCommand.ExecuteNonQuery();
  myTrans.Commit();
  Console.WriteLine("Both records are written to database.");
  // }
  // catch (Exception e)
  //{
  myTrans.Rollback();
  /// throw e;
  //Console.WriteLine(e.ToString());
  Console.WriteLine("Neither record was written to database.");
  // }
  //finally
  //{
  myConnection.Close();
  //}
  }

------解决方案--------------------
using(TransactionScope scope = new TransactionScope()) { 
//方法1 //方法2: scope.Complete(); }