Global Data Management Forum

 View Only
  • 1.  IBM DB2 ERROR when Transaction SaveChanges EF CORE for .NET 6

    Posted Mon May 15, 2023 06:27 PM

    I migrated from 3.1 to 6.0 and I have an issue every time I do Context.SaveChanges() after modifications made inside a Transaction using BOSContext.Database.BeginTransaction() .. It was working fine in 3.1.
    Error:
    IBM.Data.Db2.DB2Exception: 'ERROR [42601] [IBM][DB2] SQL0104N  An unexpected token "<END-OF-STATEMENT>" was found following "".  Expected tokens may include:  "ON UNIQUE".'

    Code example:
                using (var transaction = SomeContext.Database.BeginTransaction()){                
                    try{
                      var obj1 = SomeContext.SomeTable.Where(x => x.SomeFieldId == 1).FirstOrDefault()
                      obj1.SomeFieldToUpdate= "New Value 1";

                      var obj2 = SomeContext.SomeTable.Where(x => x.SomeFieldId == 2).FirstOrDefault()
                      obj2.SomeFieldToUpdate= "New Value 2";

                      BOSContext.SaveChanges(); //=> Fails here
                      transaction.Commit();                      
                    } catch (Exception){
                        transaction.Rollback();
                        throw;
                    }                
                }
    I had to change the license to support 11.5 and to be compatible with 6.0.300 
    The connection string is the same as before...
    Transactions work as long as you don't do SaveChanges to persist data
    SaveChanges work if they are not inside a transaction.
    I put a DbTransactionInterceptor and the execution fails between CreatingSavepoint and CreateSavepoint ... The transaction SupportSavepoints is generated as true but the IBMConnection SupportSavepoint is false ... I am not sure if this might be the reason 
    I created a .dmp file and .flw respectively, but there is no meaningful information ...  
    The error message is not explained in the IBM documentation and no other traceable information is generated from the package. I tried traceLevel=ALL but the license doesn't allow it. 



    ------------------------------
    Albert Sosa
    ------------------------------


  • 2.  RE: IBM DB2 ERROR when Transaction SaveChanges EF CORE for .NET 6

    Posted Wed May 17, 2023 02:15 AM

    Hi Albert,
    Thanks for reaching out to us..
    We tried to reproduce the issue but could not reproduce it in our house.
    We implemented Console app which targets .NET 6.0, EF Core package 6.0.0.300 and LUW Server
    Application contains table which has 2 column 1. ID integer type and 2. Name String type..
    Here is sample code which we tried:

    var ctx = new MyContext();
    using (var trans = ctx.Database.BeginTransaction())
    {
        try
        {
            //ctx.SVPTAB1s.Add(new SVPTAB1 { ID = 102, Name = "archana" });
            var q = ctx.SVPTAB1s.Where(s => s.ID == 101).FirstOrDefault();
            q.Name = "XYZ";
            trans.CreateSavepoint("MySavePoint");
    
            var q1 = ctx.SVPTAB1s.Where(s => s.ID == 102).FirstOrDefault();
            q1.Name = "ABC";
    
            ctx.SaveChanges();
            trans.Commit();
        }
        catch (Exception e)
        {
            trans.Rollback();
            throw;
    
        }
    }

    Could you share following data points to investigate further..
    1. What is target server details ?
    2. Could you please share non confidential Repro app along with dummy database objects.? If you can not share the requested data here Please reach out to IBM Support team that will expedite the process as well...

    Regards,
    Archana



    ------------------------------
    Archana Soni
    ------------------------------



  • 3.  RE: IBM DB2 ERROR when Transaction SaveChanges EF CORE for .NET 6

    Posted Tue June 20, 2023 10:38 AM

    I put a DbTransactionInterceptor and the execution fails between CreatingSavepoint and CreateSavepoint

    The transaction SupportSavepoints is generated as true but the IBMConnection SupportSavepoint is false.

    I am not sure if this might be the reason 
    I created a .dmp file and .flw respectively, but there is no meaningful information ...  

    The error message is not explained in the IBM documentation and no other traceable information is generated from the package.

    I tried traceLevel=ALL but the license doesn't allow it. 



    ------------------------------
    Raja Adil
    ------------------------------



  • 4.  RE: IBM DB2 ERROR when Transaction SaveChanges EF CORE for .NET 6

    IBM Champion
    Posted Wed June 21, 2023 06:49 AM
    Edited by Youssef Sbai Idrissi Wed June 21, 2023 06:49 AM

    The error message you are getting is IBM.Data.Db2.DB2Exception: 'ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "<END-OF-STATEMENT>" was found following "". Expected tokens may include: "ON UNIQUE".'. This error occurs when DB2 encounters an unexpected token in a SQL statement. In your case, the unexpected token is "<END-OF-STATEMENT>". This token is not expected in the SQL statement that is being executed by the Context.SaveChanges() method.

    The reason why you are getting this error is because of the change in license. The new license does not support savepoints, which is what the Context.SaveChanges() method uses to persist data in a transaction.

    There are a few things you can do to fix this issue. One option is to downgrade to the old license. Another option is to use the DbTransactionInterceptor to create a savepoint manually. You can also try to increase the trace level to get more information about the error.

    You can implement it within your code to handle it manually. Hope this gives you an idea where to start !



    ------------------------------
    Youssef Sbai Idrissi
    Software Engineer
    ------------------------------