ORA-01000:超出打开游标的最大数 的解决办法(C#)

C#包装了一个数据库操作类,提供一个批量执行sql的函数,执行中遇到【ORA-01000:超出打开游标的最大数 的解决办法】的错误。

查看MSDN的ADODB.Connection的函数Execute说明,发现是调用时一个参数的问题。下面是我包装的函数:

public bool ExecuteSql(string[] strSqlArray)
        {
            try
            {
                m_cn.BeginTrans();
                for (int i = 0; i < strSqlArray.Length; i++ )
                {
                    object objAffected;
                    m_cn.Execute(strSqlArray[i], out objAffected, 0); //参数【0】捣的鬼
                }
                m_cn.CommitTrans();
                return true;
            }
            catch (System.Exception e)
            {
                MsgBoxCtrl.MsgBoxException(e.Message, "CDatabase.ExecuteSql");
                if (m_cn.State == (int)ConnectionState.Open)
                {
                    try
                    {
                        m_cn.RollbackTrans();
                    }
                    catch (System.Exception e1)
                    {
                        MsgBoxCtrl.MsgBoxException(e1.Message, "CDatabase.ExecuteSql");
                    }
                }
                return false;
            }
        }

将上面的Execute调用改一下就Ok了

m_cn.Execute(strSql, out objAffected, (int)ADODB.ExecuteOptionEnum.adExecuteNoRecords);

下面是MSDN的说明:

Using the Execute method on a Connection Object (ADO) object executes whatever query you pass to the method in the CommandText argument on the specified connection. If the CommandText argument specifies a row-returning query, any results that the execution generates are stored in a new Recordsetobject. If the command is not intended to return results (for example, an SQL UPDATE query) the provider returns Nothing as long as the option adExecuteNoRecords is specified; otherwise Execute returns a closed Recordset.

MSDN链接地址:https://msdn.microsoft.com/en-us/library/windows/desktop/ms675023(v=vs.85).aspx

你可能感兴趣的:(oracle,游标,ORA-01000)