tags:

views:

360

answers:

1

The code below is just a test to connect to an Oracle database and fill data to a DataTable. After executing the statement da.Fill(dt);, I always get the exception "Exception of type 'System.OutOfMemoryException' was thrown.". Has anyone met this kind of error? My project is running on VS 2005, and my Oracle database version is 11g. My computer is using Windows Vista. If I copy this code to run on Windows XP, it works fine.

Thank you.

using System.Data;
using Oracle.DataAccess.Client;

...

string cnString = "data source=net_service_name; user id=username; password=xxx;";
OracleDataAdapter da = new OracleDataAdapter("select 1 from dual", cnString);

try
{
   DataTable dt = new DataTable();
   da.Fill(dt);  // Got error here
   Console.Write(dt.Rows.Count.ToString());

}
catch (Exception e)
{
   Console.Write(e.Message); // Exception of type 'System.OutOfMemoryException' was thrown.
}

Update

I have no idea what happens to my computer. I just reinstall Oracle 11g, and then my code works normally.

A: 

How big is your dual table? This query:

select 1 from dual

Will return a single-column table with as many rows as the dual table, with 1 in every row. If the table has millions of rows then it wouldn't surprise me if it threw an out of memory exception.

Edit Of course, this doesn't explain why it would work on XP but not on Vista, unless it's something implementation-specific (querying a different instance of the database on the two different workstations, for example).

Edit 2:

Ok, so presumably there is only one row in dual since your comment indicates that the query only returns a single row.

A couple of things to investigate:

  1. The Oracle ADO.NET connection requires the Oracle client software, right? Is the Oracle software on your Vista box the same version as on the XP box? Perhaps there's a discrepancy there.

  2. Instead of showing e.Message, try showing e.ToString() to get a full stack trace - it might give you more insight as to where the error is being thrown from.

Matt Hamilton
The query returns only 1 row, and the value is 1.
Sambath
In Oracle you cannot write "select 1" like in MS SQL Sever. But there is a dual "pseudotable", so you can write "select 1 from dual" and get the same result. See: "http://en.wikipedia.org/wiki/DUAL_table".
Tomek Szpakowicz
Ah good to know - thanks @tomekszpakowicz!
Matt Hamilton