MySql Transaction

Posts   
 
    
Luca75
User
Posts: 37
Joined: 10-Feb-2012
# Posted on: 15-Feb-2017 20:34:50   

Hello guys I'm working I have a strange problem when I go save the amount of the transaction is in MySQL .. rolback no apparent reason. I tried to save without transaction and everything works properly. The query that the DQE is correct, and if I run from scritp sql works well .. Do you have any idea where he might be the problem? Thank you


public AziendeResponse Any(UpdateAziende request)
        {
            KendoAziende.DaoClasses.CommonDaoBase.CommandTimeOut = 600;
            var dtos = request.Aziende;
            var metaData = new LinqMetaData();
            // fetch the entities from the DB
            var entities = metaData.enetAziende
                                    .Where(DtoEnetAziendePersistence.CreatePkPredicate(dtos))
                                    .ToList();
            var uow = new UnitOfWork();
            foreach (var dto in dtos)
            {
                // find the entity the current dto derived from, using in-memory pk filter
                var entity = entities
                                .FirstOrDefault(DtoEnetAziendePersistence.CreateInMemoryPkPredicate(dto));
                if (entity == null)
                {
                    // new entity
                    entity = new enetAziendeEntity();
                }
                // update entity with values of dto
                entity.UpdateFromDtoEnetAziende(dto);
                // log for persistence
                uow.AddForSave(entity);
                //entity.Save();
            }
            // persist all changed entities in one transaction
            using (var trans = new Transaction(IsolationLevel.ReadCommitted, "Update DTOs"))
            {
                uow.Commit(trans);
            }

                                
            AziendeResponse Result = new AziendeResponse();
            return Result;

        }

Query from script is ok..


START TRANSACTION;
UPDATE `gc7jo_modkendoenet_aziende` SET `approvato_da`="9999999" WHERE ( ( `gc7jo_modkendoenet_aziende`.`id` = 1));
COMMIT;

Trace:


Executed Sql Query: 
    Query: SELECT `LPA_L1`.`approvato` AS `Approvato`, `LPA_L1`.`approvato_da` AS `ApprovatoDa`, `LPA_L1`.`azienda_logo` AS `AziendaLogo`, `LPA_L1`.`cap` AS `Cap`, `LPA_L1`.`descrizione` AS `Descrizione`, `LPA_L1`.`email` AS `Email`, `LPA_L1`.`fax` AS `Fax`, `LPA_L1`.`id` AS `Id`, `LPA_L1`.`id_tipologia_azienda` AS `IdTipologiaAzienda`, `LPA_L1`.`indirizzo` AS `Indirizzo`, `LPA_L1`.`pec` AS `Pec`, `LPA_L1`.`pubblicato` AS `Pubblicato`, `LPA_L1`.`ragione_sociale` AS `RagioneSociale`, `LPA_L1`.`telefono` AS `Telefono` FROM `gc7jo_modkendoenet_aziende`  `LPA_L1`  WHERE ( ( `LPA_L1`.`id` IN (@p1, @p2)))
    Parameter: @p1 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.
    Parameter: @p2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 2.

Method Exit: DaoBase.ExecuteMultiRowRetrievalQuery
Method Exit: DaoBase.PerformGetMultiAction
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: already refetching or isdirty.
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: EntityBase.CheckForRefetch
Method Exit: EntityBase.CheckForRefetch: state is not OutOfSync
Method Enter: TransactionBase.CTor
:   Transaction name: Update DTOs. Isolation level: ReadCommitted.
Method Exit: TransactionBase.CTor
Method Enter: UnitOfWork.Commit(2)
:   Transaction to use: Update DTOs. AutoCommit: False
:   Handling Pre Insert CallBacks.
:   Handling Inserts.
:   Handling Pre Update CallBacks.
:   Handling Updates.
Method Enter: DaoBase.PersistQueue
Persistence action info: Action: Update. Queue length: 2
Current persisted entity info: 
    Entity: KendoAziende.EntityClasses.enetAziendeEntity. ObjectID: a32f9b9e-3e49-46c7-bce7-40ba10db082c
    PrimaryKey field: Id. Type: System.Int32. Value: 1
Method Enter: DaoBase.UpdateExisting(3)
Method Enter: CreateUpdateDQ(5)
Method Enter: CreateSingleTargetUpdateDQ(4)
Generated Sql query: 
    Query: UPDATE `gc7jo_modkendoenet_aziende` SET `approvato_da`=@p1 WHERE ( ( `gc7jo_modkendoenet_aziende`.`id` = @p2))
    Parameter: @p1 : AnsiString. Length: 255. Precision: 0. Scale: 0. Direction: Input. Value: "9999".
    Parameter: @p2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.

Method Exit: CreateSingleTargetUpdateDQ(4)
Method Exit: CreateUpdateDQ(5)
Method Enter: DaoBase.ExecuteActionQuery
Method Enter: Query.ReflectOutputValuesInRelatedFields
Method Exit: Query.ReflectOutputValuesInRelatedFields: no parameter relations.
Method Enter: Query.ReflectOutputValuesInParameterValues
Method Exit: Query.ReflectOutputValuesInParameterValues: no output parametervalues.
Executed Sql Query: 
    Query: UPDATE `gc7jo_modkendoenet_aziende` SET `approvato_da`=@p1 WHERE ( ( `gc7jo_modkendoenet_aziende`.`id` = @p2))
    Parameter: @p1 : AnsiString. Length: 255. Precision: 0. Scale: 0. Direction: Input. Value: "9999".
    Parameter: @p2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.


Executed Sql Query: 
    Query: UPDATE `gc7jo_modkendoenet_aziende` SET `approvato_da`=@p1 WHERE ( ( `gc7jo_modkendoenet_aziende`.`id` = @p2))
    Parameter: @p1 : AnsiString. Length: 255. Precision: 0. Scale: 0. Direction: Input. Value: "9999".
    Parameter: @p2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.

Query Execution Result: 1
Method Exit: DaoBase.ExecuteActionQuery
Query Execution Result: True
Method Exit: DaoBase.UpdateExisting(3)
PersistQueue method result: queuePersisted result: True
Method Exit: DaoBase.PersistQueue
:   Handling UpdateMulti Calls.
:   Handling Pre Delete CallBacks.
:   Handling Deletes.
:   Handling Post Delete CallBacks.
:   Handling DeleteMulti Calls.
Method Enter: UnitOfWork.Reset
Method Exit: UnitOfWork.Reset
Method Exit: UnitOfWork.Commit(2)
Method Enter: TransactionBase.Rollback
Method Enter: TransactionBase.Reset
Method Exit: TransactionBase.Reset
Method Exit: TransactionBase.Rollback


daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Feb-2017 05:52:36   

In this code:

using (var trans = new Transaction(IsolationLevel.ReadCommitted, "Update DTOs"))
{
    uow.Commit(trans);
}

..you have to pass true to the autoCommit parameter:

uow.Commit(trans, true);

... otherwise you have to commit the transaction manually later:

uow.Commit(trans);
trans.Commit();

This is explained in more detail in the documentation.

David Elizondo | LLBLGen Support Team
Luca75
User
Posts: 37
Joined: 10-Feb-2012
# Posted on: 16-Feb-2017 18:46:19   

Thanks!smile