I want to lock a record to prevent nobody can update while I using.
but after lock record, even myself can not update the locked record 🙁
Do I have to unlock before I update the record?
or is there a way to update the record that I locked myself?
string query = "SELECT * FROM table1";
AdsCommand cmd = conn.CreateCommand();
cmd.CommandText = query;
AdsExtendedReader reader = cmd.ExecuteExtendedReader();
reader.Read();
int recordNo = reader.RecordNumber;
reader.LockRecord(recordNo);
// do something with table1 record
// while doing something, I need to lock the record before I update record
AdsCommand cm = new AdsCommand("UPDATE table1 SET field1 = 'UPDATED'", conn);
cm.ExecuteNonQuery();
It is not possible to share a record lock between a table that is opened “directly” (as opposed to through an SQL operation) and SQL operations or other table instances.
One possibility would be to do the update through the extended reader after the lock is obtained. You could use SetString or SetValue.
Another possibility might be to update the record in a transaction. Then that record will be kept locked by that user until the transaction is committed. For example, you could use something like the following statement as a “no-op” (assuming no triggers are involved) to lock a record in a transaction without modifying the data: