Command Parameters with direct mode
Posted: Mon 11 May 2009 20:41
Hello,
I use the standard edition of dotConnect for Oracle and tried the following code once with direct=true in the connection string, and once with direct=false :
*******
OracleConnection con = new OracleConnection(connectionString);
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "insert into T_PROJECT_SESSION(C_USER_ID,C_TIMESTAMP,C_PROJECT_ID,C_PROJECT_SESSION_ID)values(:p1,:p2,:p3,SEQ_T_PROJECT_SESSION.nextval);"
+"select SEQ_T_PROJECT_SESSION.CurrVal into :p0 from DUAL;\n";
cmd.CommandText += "insert into PATENTREPORT.T_TEST_PARAM(PARAM)values(:p0);\n";
cmd.CommandText = "declare\n begin\n" + cmd.CommandText + " end;";
// Parameters
OracleParameter param0 = cmd.CreateParameter();
param0.DbType = System.Data.DbType.Int32;
param0.Direction = System.Data.ParameterDirection.Output;
param0.ParameterName = "p0";
param0.Value = null;
cmd.Parameters.Add(param0);
OracleParameter param1 = cmd.CreateParameter();
param1.DbType = System.Data.DbType.String;
param1.Direction = System.Data.ParameterDirection.Input;
param1.ParameterName = "p1";
param1.Value = "user";
cmd.Parameters.Add(param1);
OracleParameter param2 = cmd.CreateParameter();
param2.DbType = System.Data.DbType.Date;
param2.Direction = System.Data.ParameterDirection.Input;
param2.ParameterName = "p2";
param2.Value = DateTime.Now;
cmd.Parameters.Add(param2);
OracleParameter param3 = cmd.CreateParameter();
param3.DbType = System.Data.DbType.Int32;
param3.Direction = System.Data.ParameterDirection.Input;
param3.ParameterName = "p3";
param3.Value = 847;
cmd.Parameters.Add(param3);
cmd.ExecuteNonQuery();
con.Commit();
con.Close();
*********
The first Insert works fine in both modes. But then it seems that in direct mode the :p0 value is Null after the SELECT INTO statement. With direct=false, the value of this parameter is the correct one (the SEQ_PROJECT_SESSION.Currval).
I red something about a bug with repeated parameters using direct mode ? Is this the problem ?
If it isn't, how can I do to make this code work correctly ?
If this code cannot work in direct mode, is there a possibility to use the Devart assemblies with direct=false but no Oracle Client (for example add the oci.dll in our Deployment, or something like that) ?
The version of dlls I use are :
Devart.Data 5.0.1.0
Devart.Data.Oracle 5.20.29.0
Thanks in advance for your response.
I use the standard edition of dotConnect for Oracle and tried the following code once with direct=true in the connection string, and once with direct=false :
*******
OracleConnection con = new OracleConnection(connectionString);
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "insert into T_PROJECT_SESSION(C_USER_ID,C_TIMESTAMP,C_PROJECT_ID,C_PROJECT_SESSION_ID)values(:p1,:p2,:p3,SEQ_T_PROJECT_SESSION.nextval);"
+"select SEQ_T_PROJECT_SESSION.CurrVal into :p0 from DUAL;\n";
cmd.CommandText += "insert into PATENTREPORT.T_TEST_PARAM(PARAM)values(:p0);\n";
cmd.CommandText = "declare\n begin\n" + cmd.CommandText + " end;";
// Parameters
OracleParameter param0 = cmd.CreateParameter();
param0.DbType = System.Data.DbType.Int32;
param0.Direction = System.Data.ParameterDirection.Output;
param0.ParameterName = "p0";
param0.Value = null;
cmd.Parameters.Add(param0);
OracleParameter param1 = cmd.CreateParameter();
param1.DbType = System.Data.DbType.String;
param1.Direction = System.Data.ParameterDirection.Input;
param1.ParameterName = "p1";
param1.Value = "user";
cmd.Parameters.Add(param1);
OracleParameter param2 = cmd.CreateParameter();
param2.DbType = System.Data.DbType.Date;
param2.Direction = System.Data.ParameterDirection.Input;
param2.ParameterName = "p2";
param2.Value = DateTime.Now;
cmd.Parameters.Add(param2);
OracleParameter param3 = cmd.CreateParameter();
param3.DbType = System.Data.DbType.Int32;
param3.Direction = System.Data.ParameterDirection.Input;
param3.ParameterName = "p3";
param3.Value = 847;
cmd.Parameters.Add(param3);
cmd.ExecuteNonQuery();
con.Commit();
con.Close();
*********
The first Insert works fine in both modes. But then it seems that in direct mode the :p0 value is Null after the SELECT INTO statement. With direct=false, the value of this parameter is the correct one (the SEQ_PROJECT_SESSION.Currval).
I red something about a bug with repeated parameters using direct mode ? Is this the problem ?
If it isn't, how can I do to make this code work correctly ?
If this code cannot work in direct mode, is there a possibility to use the Devart assemblies with direct=false but no Oracle Client (for example add the oci.dll in our Deployment, or something like that) ?
The version of dlls I use are :
Devart.Data 5.0.1.0
Devart.Data.Oracle 5.20.29.0
Thanks in advance for your response.