OutOfMemoryException error

OutOfMemoryException error

Postby tankervin » Wed 11 Feb 2009 06:48

Hi there! I'm a newbie at this, so first I apologize if my question is too naive.

I have used the code below together with C# (VS 2005)

/* create Oracle Connection String */
OracleConnectionStringBuilder oraCSB = new OracleConnectionStringBuilder();
oraCSB.Server = "";
oraCSB.Port = 1521;
oraCSB.Sid = "GL61";
oraCSB.UserId = "databaseuser";
oraCSB.Password = "manager";
//oraCSB.MaxPoolSize = 150;
//oraCSB.ConnectionTimeout = 30;
OracleConnection vinax_connect = new OracleConnection(oraCSB.ConnectionString);

/* open Oracle Connection */
OracleCommand cmd = vinax_connect.CreateCommand();
cmd.CommandText = "SELECT * FROM TABLE_1 WHERE SALES_KEY = '" + textBox1.Text.Trim() + "'";
DataSet testDataSet = new DataSet();
OracleDataAdapter myAdapter = new OracleDataAdapter(cmd.CommandText, vinax_connect);
myAdapter.Fill(testDataSet, "Table");
dataGrid1.DataSource = testDataSet.Tables[0];
textBox1.Text = "";

Here's my problem : The above sometimes returns a OutOfMemoryException error on the myAdapter.Fill(testDataSet, "Table") statement. I have several databases (all having the same table with different amounts of data) and by changing the connection String parameters, I can rerun the same program for multiple databases. Some of these work ok while others return the OutOfMemoryException. I've tried controlling the FetchSize parameter but it does not seem to work. The databases are all Oracle 10g, so I really don't get this issue. Is there any additional setting that I have to set?

Thanks in advance
Posts: 4
Joined: Fri 06 Feb 2009 06:52

Postby Shalex » Wed 11 Feb 2009 13:06

Probably, this error appears because of too large result set that you are placing into DataTable of your DataSet object. The difference between DataReader and DataTable is the following: DataReader reads data by one row, and removes it from its cache memory after reading; DataTable doesn't remove its records. So, if you place much records into your DataTable and not clear it, there will be a point when the memory is over.

We recommend you to use, for example, the FillPage() method of the OracleDataAdapter object to control the amount of data you want to receive, and to call the Clear() method of the OracleDataTable object if you don't need its content any more.
Devart Team
Posts: 7308
Joined: Thu 14 Aug 2008 12:44

Thank you

Postby tankervin » Thu 12 Feb 2009 01:02

Thank you very much. I'll look into this.
Posts: 4
Joined: Fri 06 Feb 2009 06:52

Return to dotConnect for Oracle