[Mono-devel-list] DbDataAdapter fix for out of memory errors when filling datasets
Keith Dreibelbis
kd at spflrc.org
Mon Aug 30 16:05:28 EDT 2004
Francisco,
I looked into this some, and ended up filing this bug: (does this sound
like the same error you are describing?)
http://bugzilla.ximian.com/show_bug.cgi?id=64674
Looking and bugzilla further, it seems there is also this similar bug,
which already has a patch. I need to check to see if it fixes the bug
I filed.
http://bugzilla.ximian.com/show_bug.cgi?id=59556
-kd
Francisco Figueiredo Jr. <fxjrlists at yahoo.com.br> wrote:
> This is a multi-part message in MIME format.
> --------------080307080205020305020202
> Content-Type: text/plain; charset=us-ascii; format=flowed
> Content-Transfer-Encoding: 7bit
>
>
> Hi all,
>
> Here is a patch for handling out of memory exceptions when trying to
> fill datasets with queries which doesn't return a resultset like
> insert,
> delete, update.
>
> The out of memory exception happens in the following line of
> DbDataAdapter.cs:
>
> around line 502.
> int[] mapping = new int[reader.FieldCount]; // mapping the reader
> indexes to the datatable indexes
>
> The problem is that when the query is an insert, update or delete, the
> FieldCount property is -1 which gives the problem.
>
> The compiler can detect when you try to create an array with a negative
> index. But when this index is in a var, the runtime doesn't handle it
> and gives the error. The error is like that:
>
>
> System.OutOfMemoryException: Out of memory.
> in (unmanaged) (wrapper managed-to-native)
> System.Object:__icall_wrapper_mono_array_new_specific (intptr,int)
> in <0x00004> (wrapper managed-to-native)
> System.Object:__icall_wrapper_mono_array_new_specific (intptr,int)
> in <0x00091> System.Data.Common.DbDataAdapter:BuildSchema
> (System.Data.IDataReader,System.Data.DataTable,System.Data.SchemaType)
> in <0x00079> (wrapper remoting-invoke-with-check)
> System.Data.Common.DbDataAdapter:BuildSchema
> (System.Data.IDataReader,System.Data.DataTable,System.Data.SchemaType)
> in <0x00086> System.Data.Common.DbDataAdapter:FillTable
> (System.Data.DataTable,System.Data.IDataReader,int,int,int&)
> in <0x000ad> (wrapper remoting-invoke-with-check)
> System.Data.Common.DbDataAdapter:FillTable
> (System.Data.DataTable,System.Data.IDataReader,int,int,int&)
> in <0x0017d> System.Data.Common.DbDataAdapter:Fill
> (System.Data.DataSet,string,System.Data.IDataReader,int,int)
> in <0x000da> System.Data.Common.DbDataAdapter:Fill
> (System.Data.DataSet,int,int,string,System.Data.IDbCommand,System.Data.
> CommandBehavior)
> in <0x00049> System.Data.Common.DbDataAdapter:Fill
> (System.Data.DataSet,string)
> in <0x0006b> (wrapper remoting-invoke-with-check)
> System.Data.Common.DbDataAdapter:Fill (System.Data.DataSet,string)
>
>
>
> May I have to add a bugzilla entry?
>
> The patch is attached.
>
> Regards,
>
> Francisco Figueiredo Jr.
>
>
>
> --------------080307080205020305020202
> Content-Type: text/x-patch;
> name="DbDataAdapter.diff"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline;
> filename="DbDataAdapter.diff"
>
> ? DbDataAdapter.diff
> Index: DbDataAdapter.cs
> ===================================================================
> RCS file:
> /cvs/public/mcs/class/System.Data/System.Data.Common/
> DbDataAdapter.cs,v
> retrieving revision 1.44
> diff -u -r1.44 DbDataAdapter.cs
> --- DbDataAdapter.cs 24 Jun 2004 16:25:02 -0000 1.44
> +++ DbDataAdapter.cs 28 Aug 2004 03:01:27 -0000
> @@ -285,25 +285,31 @@
> try {
> string tableName = srcTable;
> do {
> - tableName = SetupSchema
> (SchemaType.Mapped, tableName);
> - if (tableName != null) {
> - // check if the table
> exists in the dataset
> - if
> (dataSet.Tables.Contains (tableName))
> - // get the
> table from the dataset
> - dataTable =
> dataSet.Tables [tableName];
> - else {
> - dataTable =
> new DataTable(tableName);
> -
> dataSet.Tables.Add (dataTable);
> - }
> -
> - if (!FillTable
> (dataTable, dataReader, startRecord, maxRecords, ref count)) {
> - continue;
> + .
> + // Non-resultset queries like
> insert, delete or update aren't processed.
> + if (dataReader.FieldCount != -1)
> + {
> + tableName =
> SetupSchema (SchemaType.Mapped, tableName);
> + if (tableName != null)
> {
> +
> + // check if
> the table exists in the dataset
> + if
> (dataSet.Tables.Contains (tableName))
> + // get
> the table from the dataset
> +
> dataTable = dataSet.Tables [tableName];
> + else {
> +
> dataTable = new DataTable(tableName);
> +
> dataSet.Tables.Add (dataTable);
> + }
> +
> + if (!FillTable
> (dataTable, dataReader, startRecord, maxRecords, ref count)) {
> +
> continue;
> + }
> +
> + tableName =
> String.Format ("{0}{1}", srcTable, ++resultIndex);
> +
> + startRecord =
> 0;
> + maxRecords = 0;
> }
> -
> - tableName =
> String.Format ("{0}{1}", srcTable, ++resultIndex);
> -
> - startRecord = 0;
> - maxRecords = 0;
> }
> } while (dataReader.NextResult ());
> }
> @@ -490,6 +496,7 @@
> private int[] BuildSchema (IDataReader reader,
> DataTable table, SchemaType schemaType)
> {
> int readerIndex = 0;
> +
> int[] mapping = new int[reader.FieldCount]; //
> mapping the reader indexes to the datatable indexes
> ArrayList primaryKey = new ArrayList ();
> ArrayList sourceColumns = new ArrayList ();
>
> --------------080307080205020305020202--
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 7549 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040830/296d1bc9/attachment.bin
More information about the Mono-devel-list
mailing list