Page 1 of 1

Problem with UniDac, CachedUpdates, MS-SQL

Posted: Mon 31 Jan 2011 13:13
by itsds
Hi i use the following method to update a table


mdQuery : TUniQuery with cachedupdates := true
SQL: select * from table

In a Procedure I do the following:

with mdQuery do begin
StartTransaction;
"ExcuteSQL"('update table set field1 = 'test' where id = 8')

mdQuery.Edit; << ERROR "Record was changed by another user" only with MS-SQL, Oracle and MySQL works fine
mdQuery.FieldByName('field1').AsString := 'test';
mdQuery.Post;

Commit;
end;


I use this Method with cachedupdates to avoid to refresh from Table cause i only change 1 Field in 100.000 Records.

at the end of all modifikations i usually call mdQuery.CancelUpdates.

Posted: Mon 31 Jan 2011 13:57
by itsds
I found the Reason on this.

With OLEDBProvider set to prSQL (i use this) You create a savepoint in MS-SQL.

I modified the Code now Savepoints are disabled for prSQL also.
-> No Error anymore

I made try mdQuery.CancelUpdates except end;

to avoid the Exception at the end which is generated caus you rollback an not existing Transaction.

Please think about using TUniQuery as a cached Container which is read only to the Database for Speed - Reasons !

best regards

Posted: Mon 31 Jan 2011 14:28
by itsds
Finally fixed:

I set

OldCachedUpdateLockMode: boolean = True; // Old behavior LockMode for the CachedUpdate mode

in dbaccess.pas

and all works fine now :)

Posted: Tue 01 Feb 2011 12:22
by AndreyZ
Hello,

It's good to see that you found a solution. If any other questions come up, please contact us.