的OracleCommand命令的ExecuteNonQuery

的OracleCommand命令的ExecuteNonQuery

本文介绍了的OracleCommand命令的ExecuteNonQuery问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须清除某些表在Oracle数据库然而,当我在与运行下面的代码

I have to clear certain tables in the oracle database however when I'm having issues with running the following code

public static void ClearDataTables(IList<string> tableNames)
        {
            string connectionString = "CONNECTIONSTRING";
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                foreach (string table in tableNames)
                {
                    OracleCommand command = connection.CreateCommand();
                    string sql = String.Format("DELETE FROM TOA_REPORTING.{0}", table);
                    command.CommandText = sql;
                    command.ExecuteNonQuery();
                }
                connection.Close();
            }
        }



我调用此方法与此列表

I am calling this method with this list

ClearDataTables(new List<string> { "GROUP_DEFINITION", "GROUP_REPORT_EMAIL_LIST", "GROUP_EQUIPMENT_GROUP_STN_XREF"});



它运行前两个表正常,但是在第三个,它卡住,并运行应用程序永远...

It runs the first two tables fine, however on the third one, it gets stuck and the application runs forever...

有趣的是,当我切换GROUP_REPORT_EMAIL_LIST和GROUP_EQUIPMENT_GROUP_STN_XREF
中的应用它击中的第二个表名后永远运行下去。

Funny thing is, when I switch "GROUP_REPORT_EMAIL_LIST" and "GROUP_EQUIPMENT_GROUP_STN_XREF"The application runs forever after the it hits the second table name.

所以在最后,该功能将永远运行下去,当它击中GROUP_EQUIPMENT_GROUP_STN_XREF。我已经验证了SQL通过测试出来的蟾蜍产生的作品。

So in conclusion, the function runs forever when it hits "GROUP_EQUIPMENT_GROUP_STN_XREF". I've verified that the SQL generated works by testing it out on toad.

任何人都遇到了这个问题?

Anyone else ran into this issue?

编辑 - 前两个表确实得到它运行时清除

EDIT - The first two tables does indeed get cleared when it runs.

解决方案

string connectionString = "CONNECTIONSTRING";
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                connection.Open();
                OracleCommand command = connection.CreateCommand();
                OracleTransaction trans = connection.BeginTransaction();
                command.Transaction = trans;
                foreach (string table in tableNames)
                {
                    string sql = String.Format("DELETE FROM TOA_REPORTING.{0}", table);
                    command.CommandText = sql;
                    command.ExecuteNonQuery();
                }
                trans.Commit();
            }



TRUNCATE将是一个非常好的解决方案,但是我没有特权这样做的!

TRUNCATE would have been a very nice solution, however I do not have the privileges to do so!

推荐答案

你忘犯蟾蜍(或任何其他客户端)的变化?一个开放的交易将使其无限期地等待。

Have you forgotten to commit your changes in Toad (or any other client)? An open transaction will cause it to wait indefinitely.

这篇关于的OracleCommand命令的ExecuteNonQuery问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 15:14