一種工作方式在ADO 各地樂觀併發問題是鎖住你的數據集,只要 編輯操作開始檢索的記錄。這種策略被稱爲 悲觀鎖定。長時間鎖通常會導致數據庫性能不佳和爭用問題,但在 情況下,應用程序不能容忍 在更新它們時更改了記錄,因此可能需要保留悲觀的 鎖定。
使用ADO,使用悲觀鎖定方案相對容易。在ADO.NET中,設置起來有點困難, 但您仍然可以在您的 應用程序中使用悲觀鎖定。然而,僅僅因爲你可以做點什麼 並不意味着你應該一直這麼做 - 我要說的關於 的解釋應該只在絕對必要的時候使用。
的悲觀鎖的基本步驟如下:
1) Create a transaction with an IsolationLevel of RepeatableRead.
2) Set the DataAdapter’s SelectCommand property to use the transaction you created.
3) Make the changes to the data.
4) Set DataAdapter’s Insert, Update, and Delete command properties to use the transaction you created.
5) Call the DataAdapter’s Update method.
6) Commit the transaction.
來源
2011-06-08 10:21:16
MUS