当前位置: 代码迷 >> .NET新技术 >> oralce 事务处理,调用这个方法,程序就死了。该怎么解决
  详细解决方案

oralce 事务处理,调用这个方法,程序就死了。该怎么解决

热度:332   发布时间:2016-04-25 01:55:03.0
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(); }
  相关解决方案