Mid From PDF ADO.NET ADO.NET

Optimistic Concurrency Control:?

Short answer: Optimistic Concurrency assumes that conflicts will be rare and allows multiple users to read and modify data without locking it.

Explain a bit more

When updating data, you compare the current data in the database with the data the user fetched earlier (usually by checking a timestamp or version number). If the data has been changed by someone else, you throw a concurrency exception. Steps: Add a timestamp or row version column to the table. When updating, check if the timestamp or row version has changed.

Example code

SqlCommand command = new SqlCommand("UPDATE Customers SET CustomerName = @CustomerName WHERE CustomerID = @CustomerID AND RowVersion = @RowVersion", connection); command.Parameters.AddWithValue("@CustomerName", customerName); command.Parameters.AddWithValue("@CustomerID", customerId); command.Parameters.AddWithValue("@RowVersion", rowVersion); If the RowVersion has changed between the time the user fetched the data and the time they attempt to update, the update will fail, and an exception will be thrown.

Real-world example (ShopNest)

ShopNest’s reporting job still uses ADO.NET for a heavy SQL query where raw performance and stored procedures matter more than EF convenience.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details