ORA-01000:超出開啟遊標的最大數 的解決辦法(C#)
阿新 • • 發佈:2019-01-24
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
MSDN連結地址:https://msdn.microsoft.com/en-us/library/windows/desktop/ms675023(v=vs.85).aspx