I am trying to insert two rows into a table (sequentiel). The first insert command is executed without any trouble. The second insert command gets stuck in the ExecuteNonQuery()
part. When I remove the returning part (OracleParameter
with Direction = Output
) both inserts are successful.
Doesn't work (executed twice in a sequence with different data each):
cmd.CommandText = "INSERT INTO table (Col1, Col2, Col3,...) VALUES (:ParamCol1, :ParamCol2, :ParamCol3,...) RETURNING ROWIDTOCHAR(ROWID) INTO :OutputROWID";
Works:
cmd.CommandText = "INSERT INTO table (Col1, Col2, Col3,...) VALUES (:ParamCol1, :ParamCol2, :ParamCol3,...)";
The output-parameter is declared and initialized like the following:
OracleParameter outputRowId = new OracleParameter(":OutputROWID", OracleDbType.Varchar2, 30) { Direction = ParameterDirection.Output })
Reference: OracleParameter
The funny thing is, it also works when I use the first method (with the returning ROWID
), but only when I rename the parameter in the second insert to i.e. :OutputROWID2
.
Any ideas on that why the execution gets stuck and how I can solve this?
EDIT:
Here the longer Code-Snippet:
using (OracleTransaction transaction = Globals.Db.Connection.BeginTransaction())
{
using (OracleCommand cmd = Globals.Db.Connection.CreateCommand())
{
cmd.BindByName = true;
cmd.CommandText = "INSERT INTO table (Col1, Col2, Col3,...) VALUES (:ParamCol1, :ParamCol2, :ParamCol3,...) RETURNING ROWIDTOCHAR(ROWID) INTO :OutputROWID";
OracleParameter outputRowId = new OracleParameter(":OutputROWID", OracleDbType.Varchar2, 30) { Direction = ParameterDirection.Output };
cmd.Parameters.Add(paramCol1, data["Col1"]);
cmd.Parameters.Add(paramCol2, data["Col2"]);
cmd.Parameters.Add(paramCol3, data["Col3"]);
...
cmd.Parameters.Add(outputRowId);
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex)
{
return;
}
}
}