dotConnect for Oracle Can lock table or record?
How to do?
dotConnect for Oracle Can lock table or record?
-
- Posts: 13
- Joined: Mon 21 Feb 2011 03:35
Please use the FOR UPDATE statement like:
Code: Select all
try
{
//Lock DataSet
cmd = new OracleCommand("SELECT * FROM myTable WHERE id = :id FOR UPDATE NOWAIT", con);
cmd.Parameters.AddWithValue("id", id);
da.SelectCommand = cmd;
da.Fill(myDt);
//Do sth. with myDt
}
catch(OracleException ex)
{
if(ex.Code == 54)
errorMessage = "Data is in use. Please try again later.";
else
errorMessage = ex.Message;
}
-
- Posts: 13
- Joined: Mon 21 Feb 2011 03:35
But we use Devart LinqConnect Model!
But we use Devart LinqConnect Model!Shalex wrote:Please use the FOR UPDATE statement like:Code: Select all
try { //Lock DataSet cmd = new OracleCommand("SELECT * FROM myTable WHERE id = :id FOR UPDATE NOWAIT", con); cmd.Parameters.AddWithValue("id", id); da.SelectCommand = cmd; da.Fill(myDt); //Do sth. with myDt } catch(OracleException ex) { if(ex.Code == 54) errorMessage = "Data is in use. Please try again later."; else errorMessage = ex.Message; }
We use Entity Developer Model Wizard?
How to do?
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
You can explicitly lock a row with the DataContext.ExecuteQuery method, e.g.,
Besides this, you can wrap a part of your code into TransactionScope:
In this case, the rows being updated will be locked until the TransactionScope object is disposed.
Please tell us if this helps.
Code: Select all
IEnumerable dept = context.ExecuteQuery
("select * from dept where deptno = 10 for update").ToList();
Code: Select all
using (TransactionScope ts = new TransactionScope()) {
MyDataContext context = new MyDataContext();
Dept dept = context.Depts.First();
... // modify dept
context.SubmitChanges();
ts.Complete();
}
Please tell us if this helps.