日期:2014-05-18  浏览次数:20992 次

BatchExecNonQuery
public static bool BatchExecNonQuery(string connString, string[] batchCmdText, bool rollBackFlag)
{
  bool flag;
  if ((batchCmdText == null) || (batchCmdText.Length == 0))
  {
  return true;
  }
  int index = 0;
  OracleConnection conn = null;
  OracleTransaction trans = null;
  try
  {
  conn = OpenConn(connString);
  trans = rollBackFlag ? conn.BeginTransaction() : null;
  OracleCommand cmd = new OracleCommand();
  index = 0;
  while ((index < batchCmdText.Length) && (batchCmdText[index] != null))
  {
  PrepareCommand(cmd, conn, trans, CommandType.Text, batchCmdText[index], null);
  cmd.ExecuteNonQuery();
  index++;
  }
  if (trans != null)
  {
  trans.Commit();
  }
  flag = true;
  }
  catch (Exception exception)
  {
  if (trans != null)
  {
  trans.Rollback();
  }
  throw new Exception("批处理出错!:" + batchCmdText[index] + "--" + exception.ToString());
  }
  return flag;
}

 

 


------解决方案--------------------
不知道你的问题在哪里
但是你的代码有问题
数据库资源未释放

C# code

 public static bool BatchExecNonQuery(string connString, string[] batchCmdText, bool rollBackFlag)
    {
        bool flag;
        if ((batchCmdText == null) || (batchCmdText.Length == 0))
        {
            return true;
        }
        int index = 0;
        OracleConnection conn = null;
        OracleTransaction trans = null;
        try
        {
            conn = OpenConn(connString);
            trans = rollBackFlag ? conn.BeginTransaction() : null;
            OracleCommand cmd = new OracleCommand();
            index = 0;
            while ((index < batchCmdText.Length) && (batchCmdText[index] != null))
            {
                PrepareCommand(cmd, conn, trans, CommandType.Text, batchCmdText[index], null);
                cmd.ExecuteNonQuery();
                index++;
            }
            if (trans != null)
            {
                trans.Commit();
            }
            flag = true;
        }
        catch (Exception exception)
        {
            if (trans != null)
            {
                trans.Rollback();
            }
            throw new Exception("批处理出错!:" + batchCmdText[index] + "--" + exception.ToString());
        }
        finally
        {
            //注意回收数据库链接资源
            if (conn != null && conn.State != ConnectionState.Closed)
            {
                conn.Close();
                conn.Dispose();
                conn = null;
            }
        }
        return flag;
    }