Why is the OracleDataReader that I'm using null?

Why is the OracleDataReader that I'm using null?

Postby bclayshannon » Fri 06 Apr 2012 00:31

With this code (DotConnect Oracle components):

Code: Select all
public List GetApplications(long userABCID) {
       List result = new List();
  try {
    using (OracleCommand command = con.CreateCommand()) {
      command.CommandType = System.Data.CommandType.StoredProcedure;
      command.CommandText = "REPORT.ApplicationPermission.GetApplicationCursor";
      // I tried getting just the Application name this way, too:
      //command.CommandText = "REPORT.ApplicationPermission.ApplicationString";
      command.ParameterCheck = true;
      command.Prepare();
      command.Parameters["iWorkerABCID"].Value = userABCID;

using (OracleDataReader reader = ((OracleCursor)command.Parameters["Result"].OracleValue).GetDataReader()) {
      while (reader.Read()) {
        result.Add(reader.GetString("AppName").ToLower());
      }
    }


...I'm getting "Object reference not set to an instance of an object"
bclayshannon
 
Posts: 29
Joined: Wed 14 Mar 2012 18:37
Location: Monterey, California

Postby Pinturiccio » Fri 06 Apr 2012 12:13

bclayshannon wrote:using (OracleDataReader reader = ((OracleCursor)command.Parameters["Result"].OracleValue).GetDataReader())

When you create parameters for your command they are not initialized. You have initialized iWorkerABCID parameter, but not the Result parameter. I do not know how your procedure works, but I assume, that 'Result' is an out parameter. And according to the logic of your code you want to get data from the database. In this case such parameter can be initialized, if you execute command.ExecuteNonQuery() before declaring OracleDataReader.

It is also necessary to add the following code before executing the command:
Code: Select all
command.Parameters["Result"].Direction = ParameterDirection.Output;
Pinturiccio
Devart Team
 
Posts: 1860
Joined: Wed 02 Nov 2011 09:44

Is declaring "Result" as an Output param really necessary?

Postby bclayshannon » Fri 06 Apr 2012 16:08

Isn't this unnecessary if you call
Code: Select all
command.Prepare();
?
bclayshannon
 
Posts: 29
Joined: Wed 14 Mar 2012 18:37
Location: Monterey, California

Postby Pinturiccio » Mon 09 Apr 2012 10:21

When you perform command.ParameterCheck = true; - the required parameters will be added and redundant parameters will be deleted after executing
Code: Select all
command.Prepare();
//or
command.ExecuteNonQuery();

command.Prepare(); creates a prepared (or compiled) version of the command on the server, but does not execute it.
For more information, please refer to
http://www.devart.com/dotconnect/oracle ... epare.html
If you want to receive some value in the "Result" parameter then you should execute the following code:
Code: Select all
command.ExecuteNonQuery();
Pinturiccio
Devart Team
 
Posts: 1860
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for Oracle