1

当我尝试drop sequence name像其他任何事务 ( insert, update, delete) 一样运行时,它不起作用。如何从 C# 程序中删除和创建序列?

这是代码

    public static bool executeQuery(string query)
    {
        bool success = false;
        DBConnection db = new DBConnection();
        db.Connect();

        if (db.GetConnectionState())
        {
            db.SetSql(query);

            if (db.ExecuteTransactions())
                success = true;
            else
                success = false;
        }
        else
            success = false;

        return success;
    }

ExecuteTransactions()以及SetSql()来自 DBConnection 类的方法,

    private OracleConnection connection;
    private OracleCommand command;
    private bool autoDisconnect;

    public bool ExecuteTransactions()
    {

        OracleTransaction transaction = null;
        bool success = false;

        try
        {
            transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);

            command.Connection = connection;
            command.Transaction = transaction;

            if (command.ExecuteNonQuery() > 0)
            {

                transaction.Commit();
                success = true;
            }
            else
            {
                transaction.Rollback();
                success = false;
            }
        }
        catch (Exception ex)
        {
            success = false;
            autoDisconnect = true;
            throw new Exception(ex.ToString());
        }
        //Cleaning
        finally
        {
            if (transaction != null)
            {
                transaction.Dispose();
            }
            if (autoDisconnect)
            {
                if (command.Parameters.Count > 0)
                {
                    foreach (OracleParameter pram in command.Parameters)
                    {
                        if (pram.Direction != ParameterDirection.ReturnValue)
                            pram.Dispose();
                    }
                }
                if (command != null)
                {
                    command.Dispose();
                }

                Dispose();
            }
        }
        return success;
    }

    public void SetSql(string sql)
    {
        command = new OracleCommand(sql);
        command.BindByName = true;

    }

我不确定问题是否出在SetSql()方法上,因为drop sequence不是 OracleCommand 吗?或者,如果它的ExecuteTransactions()方法,在这条线附近的某个地方if (command.ExecuteNonQuery() > 0)

谢谢!


编辑:这是错误

An exception of type 'System.Exception' occurred in TDS1.exe but was not handled in user code


Additional information: System.InvalidOperationException: OracleCommand.CommandText is invalid


   at Oracle.ManagedDataAccess.Client.OracleCommand.DoPreExecuteProcessing(OracleDependencyImpl orclDependencyImpl, Boolean bXmlQuerySave)


   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()

它在线上说if (command.ExecuteNonQuery > 0)

4

0 回答 0