Db2

 View Only
  • 1.  DB2 .net core 7causing issues

    Posted Mon May 22, 2023 02:08 PM
    Edited by Kristen Park Wed May 24, 2023 11:04 AM

    We upgraded our .net core solution from .net 5 to .net 7. We also upgraded to IBM.EntityFrameworkCore and DB2 IBM.EntityFrameworkCore-lnx from 5 to 7.

    We have a table with 57 columns. While inserting 38 rows, the following query is generated.

    Failed executing DbCommand (16ms) [Parameters=[@p0=NULL (Size = 500), @p1=NULL (Size = 200)... , @p2051=NULL (DbType = Decimal)], CommandType='"Text"', CommandTimeout='600']
    SELECT Id FROM NEW TABLE (INSERT INTO TABLE (...)
    VALUES (@p0, @p1..., @p2164, @p2165));

    In the insert statement, there are 2051 parameters(36 rows) and 2165 values(38 rows).

    Therefore, we get the following error.

    Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
     ---> System.IndexOutOfRangeException: An DB2Parameter with ParameterName '@p2165' is not contained by this DB2ParameterCollection.
       at IBM.Data.Db2.DB2ParameterCollection.RangeCheck(String parameterName)
       at IBM.Data.Db2.DB2ParameterCollection.ResetCursorOutputParamDR(List`1 namedParamList)
       at IBM.Data.Db2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation)
       at IBM.Data.Db2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method)
       at IBM.Data.Db2.DB2Command.ExecuteReader(CommandBehavior behavior)
       at IBM.Data.Db2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
    --- End of stack trace from previous location ---
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
    Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
     ---> System.IndexOutOfRangeException: An DB2Parameter with ParameterName '@p2165' is not contained by this DB2ParameterCollection.
       at IBM.Data.Db2.DB2ParameterCollection.RangeCheck(String parameterName)
       at IBM.Data.Db2.DB2ParameterCollection.ResetCursorOutputParamDR(List`1 namedParamList)
       at IBM.Data.Db2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation)
       at IBM.Data.Db2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method)
       at IBM.Data.Db2.DB2Command.ExecuteReader(CommandBehavior behavior)
       at IBM.Data.Db2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
    --- End of stack trace from previous location ---
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at IBM.EntityFrameworkCore.Update.Internal.Db2BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
    Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in System.Private.CoreLib.dll

    We don't have this issue for smaller tables.

    What's causing this? Is there some restriction added?

    Thanks

    Update:
    Following is how DB EF core 5 worked. Insert statements are broken in batches after 2051.

    Executed DbCommand (204ms) [Parameters=[@p0=NULL (Size = 500), @p1=NULL (Size = 200)... , @p2051=NULL (DbType = Decimal)], CommandType='"Text"', CommandTimeout='600']
    SELECT Id FROM NEW TABLE (INSERT INTO TABLE (...)
    VALUES (@p0, @p1..., @p2164, @p2051));

     Executed DbCommand (9ms) [Parameters=[@p2052='?' (Size = 500), @p2053='?' (Size = 200),...@p2107='?' (Size = 16) (DbType = Decimal), @p2108='?'], CommandType='"Text"', CommandTimeout='600']
    SELECT Id FROM NEW TABLE (INSERT INTO TABLE (...)
    VALUES (@p2052, @p2053..., @p2107, @p2108));

    ------------------------------
    Amit Dhakre
    ------------------------------



  • 2.  RE: DB2 .net core 7causing issues

    IBM Champion
    Posted Tue May 23, 2023 05:48 AM

    It may be a long shot - but there is a limit  (up to 2048 - depending on page size) of maximum number of parameters in INSERT statement.



    ------------------------------
    Jan Nelken
    ------------------------------