Query parameters and direct connection
Posted: Fri 06 Oct 2006 10:08
Hi all,
i'm trying to execute a simple query with a parameter inside with no success. It works perfectly if i use oracle client to connect to the DB but i need to use direct mode and in this scenario it always generates an exception with Exception.Message=NULL.
Here's the code:
OracleConnection Con = new OracleConnection("User ID=USER; Password=PASSWORD; Direct=true; Data Source=MainDB.Domain.com; Port=1521; SID=MAINDB;");
Con.Open();
OracleCommand Cmd = new OracleCommand();
Cmd.Connection=Con;
Cmd.CommandText="begin\n select username from users where password=:password; \nend;";
OracleParameter p=new OracleParameter();
p.ParameterName=":password";
p.OracleDbType=OracleDbType.VarChar;
p.Direction=ParameterDirection.Input;
p.Value="mypwd";
Cmd.Parameters.Add(p);
OracleDataReader res = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
the last line generates an excpetion and as i said it works ok if i don't use direct mode (but i need to use it).
Of course there's something wrong with parameters because if i insert the pwd in the query it works ok.
i'm using oradirect.net 3.20.7.0 with BDS2006
any help?
thanks in advance.
Fulvio
i'm trying to execute a simple query with a parameter inside with no success. It works perfectly if i use oracle client to connect to the DB but i need to use direct mode and in this scenario it always generates an exception with Exception.Message=NULL.
Here's the code:
OracleConnection Con = new OracleConnection("User ID=USER; Password=PASSWORD; Direct=true; Data Source=MainDB.Domain.com; Port=1521; SID=MAINDB;");
Con.Open();
OracleCommand Cmd = new OracleCommand();
Cmd.Connection=Con;
Cmd.CommandText="begin\n select username from users where password=:password; \nend;";
OracleParameter p=new OracleParameter();
p.ParameterName=":password";
p.OracleDbType=OracleDbType.VarChar;
p.Direction=ParameterDirection.Input;
p.Value="mypwd";
Cmd.Parameters.Add(p);
OracleDataReader res = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
the last line generates an excpetion and as i said it works ok if i don't use direct mode (but i need to use it).
Of course there's something wrong with parameters because if i insert the pwd in the query it works ok.
i'm using oradirect.net 3.20.7.0 with BDS2006
any help?
thanks in advance.
Fulvio