Recently encountered a problem in the project, transaction lock.
Transactionoptions tos = new Transactionoptions ();
Tos. IsolationLevel = Isolationlevel.repeatableread; A row lock locks only the row of data for the current operation, and other data for the current table is not affected. (verified)
isolationlevel.serializable; Table lock the current operation will lock the entire table, only after the transaction commits, the data of the table can be manipulated (verified)
"SELECT * from tableName where id = 1 for update"; Use for update when querying, the current data row can still be updated, but when the thing is not committed, the other transaction re-operation of the table will lock the row, you need to wait for the transaction to be committed before it can be manipulated and committed (not verified)
Tos. Timeout = new TimeSpan (0, 2, 0);
using (TransactionScope ts = new TransactionScope (transactionscopeoption.required, TOS))
{
Business Processing
Initstockqty (item);
Ts.complete ();
}
Remember database transaction lock once