Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How many ways are there to implement locking in ADO.NET
How many ways are there to implement locking in ADO.NET ?
✍: Guest
Following are the ways to implement locking using ADO.NET
1. When we call gUpdateh method of DataAdapter it handles locking internally.
If the DataSet values are not matching with current data in Database it raises
concurrency exception error. We can easily trap this error using Try..Catch
block and raise appropriate error message to the user.
2. Define a Datetime stamp field in the table.When actually you are firing the
UPDATE SQL statements compare the current timestamp with one existing
in the database. Below is a sample SQL which checks for timestamp before
updating and any mismatch in timestamp it will not update the records. This is
the best practice used by industries for locking.
Update table1 set field1=@test where LastTimeStamp=@CurrentTimeStamp
3. Check for original values stored in SQL SERVER and actual changed values.
In stored procedure check before updating that the old data is same as the
current. Example in the below shown SQL before updating field1 we check
that is the old field1 value same. If not then some one else has updated and
necessary action has to be taken.
Update table1 set field1=@test where field1 = @oldfield1value
Locking can be handled at ADO.NET side or at SQL SERVER side i.e. in stored
procedures. For more details of how to implementing locking in SQL SERVER read
gWhat are different locks in SQL SERVER ?h in SQL SERVER chapter.
2007-10-24, 5838👍, 0💬
Popular Posts:
What is application domain? Explain. An application domain is the CLR equivalent of an operation sys...
How can I enable session tracking for JSP pages if the browser has disabled cookies? We know that se...
What is AL.EXE and RESGEN.EXE? In the previous question you have seen how we can use resource files ...
When should the method invokeLater() be used? This method is used to ensure that Swing components ar...
How To Control Horizontal Alignment? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells By...