调用批量合并时的ORA-12537 - Oracle.ManagedDataAccess.Client

时间:2014-04-17 00:39:37

标签: c# oracle oracle11g bulkinsert odp.net

我正在尝试使用ArrayBindCount插入/更新许多记录。

它适用于1和2条记录,但如果我尝试插入 3 或更多,我会得到 ORA-12537 例外。

我正在使用 Oracle.ManagedDataAccess.dll 版本 4.121.1.0 。 我也尝试了 OracleXE 11g Oracle Standard 11g

这是我正在使用的sql:

MERGE INTO tb_medidor_ene t1 
USING (select :pId cd_medidor, :pDate dt_hr_instante, :pValor vl_eneat_del from dual) t2 ON (t1.cd_medidor = t2.cd_medidor and t1.dt_hr_instante = t2.dt_hr_instante) 
WHEN MATCHED THEN update set t1.vl_eneat_del = t2.vl_eneat_del, dt_hr_insercao = :pInsertDate 
WHEN NOT MATCHED THEN INSERT (t1.cd_medidor, t1.dt_hr_insercao, t1.dt_hr_instante, t1.vl_eneat_del) 
VALUES (t2.cd_medidor, :pInsertDate, t2.dt_hr_instante, t2.vl_eneat_del)

这个(简化的)代码:

    int num = 3;
    int index;
    var ids = new int[num];
    var insertDates = new DateTime[num];
    var dates = new DateTime[num];
    var values = new double[num];

    for (index = 0; index < num; index++) {
        ids[index] = 1;
        insertDates[index] = DateTime.Now;
        dates[index] = DateTime.Today.AddMinutes(index * 5);
        values[index] = index;
    }
    using (var conn = new OracleConnection(Program.ConnString)) {
        conn.Open();
        using (var command = conn.CreateCommand()) {
            command.ArrayBindCount = num;
            command.CommandText = sql;
            command.BindByName = true;
            command.Parameters.Add(new OracleParameter("pId", ids));
            command.Parameters.Add(new OracleParameter("pInsertDate", insertDates));
            command.Parameters.Add(new OracleParameter("pDate", dates));
            command.Parameters.Add(new OracleParameter("pValor", values));
            command.ExecuteNonQuery();
        }
    }

“Oracle.ManagedDataAccess.dll中发生了'Oracle.ManagedDataAccess.Client.OracleException'类型的未处理异常”

{“ORA-12537:Biblioteca de Rede:Fim do arquivo”}

堆栈跟踪:

at Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel level,OracleTraceTag tag,Exception ex)    at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor []&amp; defineAccessors,Accessor [] bindAccessors,Boolean bHasReturningParams,SQLMetaData&amp; sqlMetaData,SqlStatementType statementType,Int64 noOfRowsFetchedLastTime,Int32 noOfRowsToFetch,Int32&amp; noOfRowsFetched,Int64&amp; queryId,Int32 longFetchSize,Int32 initialLOBFetchSize ,Int64 [] scnFromExecution,Boolean&amp; bAllPureInputBinds,DataUnmarshaller&amp; dataUnmarshaller,MarshalBindParameterValueHelper&amp; marshalBindParamsHelper,Boolean bDefineDone)    at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText,OracleParameterCollection paramColl,CommandType commandType,OracleConnectionImpl connectionImpl,Int32 longFetchSize,Int32 lobPrefetchSize,OracleDependencyImpl orclDependencyImpl,Int64 []&amp; scnFromExecution,OracleParameterCollection&amp; bindByPositionParamColl,Boolean&amp; bBindParamPresent,Boolean isFromEF)    在Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()    at OraclePlayground.Program.Main(String [] args)在c:\ dev \ way2 \ DataIn \ OraclePlayground \ OraclePlayground \ Program.cs:第114行    在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)    在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)    在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)    在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)    在System.Threading.ThreadHelper.ThreadStart()

2 个答案:

答案 0 :(得分:0)

对于有同样问题的人:

我最终创建了一个存储过程,它只执行我试图直接执行的相同SQL。

然后,您可以批量调用该过程,它可以正常工作。

到目前为止,这是唯一的方法,直到Oracle人员解决问题。

答案 1 :(得分:0)

我有类似的问题。合并的项目导致ORA-12537错误。这很奇怪,因为它工作了一段时间,然后没有。我最终将它缩小到CLOB字段中的空值。如果只有CLOB的一个值为null,它将起作用,但如果有多个值,它将一直死亡。我通过更改它来解决它,以便在CLOB中添加空格(即使使用&#39;&#39;导致错误)。浪费空间,但至少错误消失了。

这对我来说似乎是个错误。我在本地运行64位的Oracle 11.2.0.3.0。希望这会有所帮助...