[Mono-list] DBNull incorrectly returned by OracleDataReader

j e todamaximum@yahoo.com
Fri, 5 Mar 2004 16:26:38 -0800 (PST)


Hello,

I'm having trouble reading data from an Oracle
database using OracleDataReader.  Values returned via
reader[0].ToString() are empty strings and
reader.GetValue(0) is returning a System.DBNull object
even though there is non-null data in the column. 
Anyone experience this problem?

Read on if you want to know the details on how I can
produce this problem...

Using:
  Mono 0.30.1
  Oracle 9i (9.2.0.3.0) client and server
  Solaris 2.8

I put together a small example that reads from
scott.emp.  The table is populated, as you can see:
   SQL> desc scott.emp 
    Name        Null?    Type
    ----------- -------- --------------
    EMPNO       NOT NULL NUMBER(4)
    ENAME                VARCHAR2(10)
    JOB                  VARCHAR2(9)
    MGR                  NUMBER(4)
    HIREDATE             DATE
    SAL                  NUMBER(7,2)
    COMM                 NUMBER(7,2)
    DEPTNO               NUMBER(2)

   SQL> SELECT ename, job FROM scott.emp;

   ENAME      JOB
   ---------- ---------
   SMITH      CLERK
   ALLEN      SALESMAN
   WARD       SALESMAN
   JONES      MANAGER
   MARTIN     SALESMAN
   BLAKE      MANAGER
   CLARK      MANAGER
   SCOTT      ANALYST
   KING       PRESIDENT
   TURNER     SALESMAN
   ADAMS      CLERK
   JAMES      CLERK
   FORD       ANALYST
   MILLER     CLERK

   14 rows selected.

Here's the output of my application:

   > mint myapp.exe

   Connecting to database...
   Connected.

   reader.GetName(0): ENAME
   reader.IsDBNull(0): False
  
reader.GetValue(0).GetType().ToString():System.DBNull
   Employee Name:   Job: 

   reader.GetName(0): ENAME
   reader.IsDBNull(0): False
  
reader.GetValue(0).GetType().ToString():System.DBNull
   Employee Name:   Job: 

   <repeats above for the 14 rows in the table>

The employee name and job should have been displayed
in the above output but are not since the reader is
incorrectly returning DBNull.


Here's my example code:

******* BEGIN CODE

using System;
using System.Data.OracleClient;

namespace database_test
{
   class my_program
   {

      [STAThread]
      static void Main(string[] args)
      {
         Console.WriteLine("Connecting to
database...");

         string connectionString = 
            "Data Source=databasenamegoeshere;" +
            "User ID=usernamegoeshere;" +
            "Password=passwordgoeshere;";
         OracleConnection dbcon = null;
         dbcon = new OracleConnection
(connectionString);
         dbcon.Open ();

         Console.WriteLine("Connected.");


         OracleCommand dbcmd = dbcon.CreateCommand ();
         string sql = "SELECT ename, job FROM
scott.emp";
         dbcmd.CommandText = sql;
         OracleDataReader reader = dbcmd.ExecuteReader
();
         while (reader.Read ()) 
         {
            Console.WriteLine("");
            Console.WriteLine("reader.GetName(0): " +
reader.GetName(0) );
            Console.WriteLine("reader.IsDBNull(0): " +
reader.IsDBNull(0) );
           
Console.WriteLine("reader.GetValue(0).GetType().ToString():"

                  +
reader.GetValue(0).GetType().ToString());

            string employeeName =
reader[0].ToString();
            string job = reader[1].ToString();
            Console.WriteLine ("Employee Name: " +
employeeName + "  Job: " + job);
         }

         reader.Close ();
         reader = null;
         dbcmd.Dispose ();
         dbcmd = null;
         dbcon.Close ();
         dbcon = null;
      }
   }
}

******* END CODE


Here's how I'm compiling my application:
   /space/opt/mono/bin/mcs myapp.cs
-lib:/space/opt/mono/lib -r:System.Data.OracleClient


Has anyone experienced this problem and solved it?

Thank you,

J


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com