我有一個表,其中包含最大值,需要由多個程序獲取和設置。如何獲取舊值並在C#中更新新內容時,如何鎖定表格一段時間?換句話說:是否可以使用ADO.NET鎖定Oracle 10g數據庫表?
string sql = "lock table MaxValueTable in exclusive mode";
using (DbCommand cmd = cnctn.CreateCommand())
{
cmd.CommandText = sql;
// execute command somehow!!
}
maxValue = GetMaxValue();
SetMaxValue(maxValue + X);
sql = "lock table MaxValueTable in share mode";
using (DbCommand cmd = cnctn.CreateCommand())
{
cmd.CommandText = sql;
// execute command somehow!!
}
廣東話」你用Oracle序列呢?它會處理同步你。 – 2010-03-05 11:54:14
@Peter郎。完美。一個序列也許馬蒂可以解釋他爲什麼不這樣做 – Guru 2010-03-05 11:56:53
@馬蒂 - 彼得的建議是健全的 - 看看http://www.techonthenet.com/oracle/sequences.php – RichardOD 2010-03-05 11:57:22