This discussion is archived
10 Replies Latest reply: Feb 5, 2013 9:23 AM by ChrisJenkins RSS

OracleDataReader : Object reference not set to an instance of an object

975714 Newbie
Currently Being Moderated
Hi,

I have a problem with executing oracleCommand.ExecuteReader() method. Whatever I try it always returns null and it won't create OracleDatareader object. I'm using ODAC 1120320_x64 for .net 4.0 and timesten112241.win64. Don't sure what to do. Debugger is showing strange thing in OracleConnection object : ConnectionState = Closed, but output of ttStatus shows connection to TimesTen data store and ExecuteNonQuery() command works just fine with or without (in or out) parameters. But when I try to execute some query with multile output such as select *, I can't get any result.
I also have a strange problem with connection.Open() and couldn't find any solution online. When I execute Open() i throws AccessViolationException that can be handled with [HandleProcessCorruptedStateExceptions] attribute, but connection is established after that and my application works fine until I try to instance OracleDataReader object. Thanks in advance!

Here is the code:
OracleCommand select = null;
OracleDataReader reader = null;

select = new OracleCommand(selectStmt, connection);
select.CommandType = CommandType.Text;
try
{
reader = select.ExecuteReader(); // this line throws NullReferenceException
if (reader.HasRows)
{
while (reader.Read())
{
object[] values = new object[1];
reader.GetValues(values);
if (values[0] != DBNull.Value)
{

SupportedTypes.Add((DMSType)values[0]);
}

}

}
else
{
Console.WriteLine("No rows found.");
}

return SupportedTypes;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return null;
}
finally
{
reader.Dispose();
select.Dispose();
}

Just to mention, I tried it with different queries (pl/sql, plane sql, stored procedure) and all of them works fine in SQL Developer, but not in app.

Best regards,
Nikola

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points