0

I'm using a C# script component with SSIS datflow to insert rows in batches. This is the code I use, but I'm getting this error:

Invalid parameter binding
Parameter name: ParameterName

These are the methods I use:

private OracleConnection conn;
private OracleCommand cmd;
private const int BATCH_SIZE = 50000;
private System.Collections.Generic.List<object[]> bufferRows;

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    List<object> rowValues = new List<object>();

    // --- Keep identical order to the SQL ---
    rowValues.Add(Row.DERCADDCOLUMNSBATCHID_IsNull ? DBNull.Value : (object)Row.DERCADDCOLUMNSBATCHID);
    rowValues.Add(Row.DERCADDCOLUMNSRECDID_IsNull ? DBNull.Value : (object)Row.DERCADDCOLUMNSRECDID);
    rowValues.Add(Row.DERCADDCOLUMNSCREADATE_IsNull ? DBNull.Value : (object)Row.DERCADDCOLUMNSCREADATE);
    bufferRows.Add(rowValues.ToArray());

    if (bufferRows.Count >= BATCH_SIZE)
        BulkInsert();
}

public override void PreExecute()
{
    base.PreExecute();

    bufferRows = new System.Collections.Generic.List<object[]>(BATCH_SIZE);
    
    string connectionString = "User Id=userid;Password=xxxx;Data Source=xxxx;";

    conn = new OracleConnection(connectionString);
    conn.Open();

    StringBuilder insertSql = new StringBuilder();
    insertSql.Append("INSERT INTO STG.tablename(");
    insertSql.Append("BATCH_ID, RECD_ID, CREA_DATE)");
    insertSql.Append("VALUES (");
    insertSql.Append(":pBATCH_ID, :pRECD_ID, :pCREA_DATE)");

    cmd = new OracleCommand(insertSql.ToString(), conn);
    cmd.BindByName = true;
    cmd.ArrayBindCount = BATCH_SIZE;

    cmd.Parameters.Add(":pBATCH_ID", OracleDbType.Varchar2, ParameterDirection.Input);
    cmd.Parameters.Add(":pRECD_ID", OracleDbType.Varchar2, ParameterDirection.Input);
    cmd.Parameters.Add(":pCREA_DATE", OracleDbType.TimeStamp, ParameterDirection.Input);
}
    
private void BulkInsert()
{
     if (bufferRows.Count == 0)
         return;

     try
     {
         int rowCount = bufferRows.Count;
         cmd.ArrayBindCount = rowCount;

         for (int i = 0; i < cmd.Parameters.Count; i++)
         {
             object[] paramValues = new object[rowCount];

             for (int j = 0; j < rowCount; j++)
             {
                 object[] row = bufferRows[j];
                 paramValues[j] = row[i] ?? DBNull.Value;
             }

             cmd.Parameters[i].Value = paramValues;
         }
        
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         bool cancel;
         this.ComponentMetaData.FireError(0, "OracleBulkInsert", ex.Message, "", 0, out cancel);
     }
     finally
     {
         bufferRows.Clear();
     }
}

I tried to remove the ":" in oracle params and re-execute. I still have the same issue. I also tried to put a breakpoint in the method bulk insert on this statemtent cmd.ExecuteNonQuery(); and it shows the same error message and no details:

Parameter name: ParameterName'

6
  • Try adding the parameters in this way: cmd.Parameters.Add("pBATCH_ID", OracleDbType.Varchar2, ParameterDirection.Input); Commented 2 days ago
  • 1
    cmd.Parameters.Add(":pBATCH_ID, OracleDbType.Varchar2, ParameterDirection.Input); is missing a closing quote and should be cmd.Parameters.Add("pBATCH_ID", OracleDbType.Varchar2, ParameterDirection.Input);. The other parameters are also missing the closing quote. Commented 2 days ago
  • Hi all, I added the quotes as suggested, but the issue persists. Is my bulk insert method correct? Commented yesterday
  • Are you getting that error in the script task itself? Or are you trying to pass a parameter to the script task in the SSIS flow where you can add variables for read and/or read/write? Maybe something is incorrect there before it even gets to the execution part of the script task? Commented yesterday
  • I'm getting the error in the script task itself exactly in the bulk insert method in this line : cmd.ExecuteNonQuery(); and this is the error : Invalid parameter binding Parameter name: ParameterName Commented yesterday

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.