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'
cmd.Parameters.Add("pBATCH_ID", OracleDbType.Varchar2, ParameterDirection.Input);
cmd.Parameters.Add(":pBATCH_ID, OracleDbType.Varchar2, ParameterDirection.Input);
is missing a closing quote and should becmd.Parameters.Add("pBATCH_ID", OracleDbType.Varchar2, ParameterDirection.Input);
. The other parameters are also missing the closing quote.