Mid
From PDF
ADO.NET
ADO.NET
How do you implement multiple transactions in ADO.NET?
Short answer: You can execute multiple transactions sequentially by managing multiple SqlTransaction objects. Each transaction can either be committed or rolled back based on the success or failure of the operations.
Example code
SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlTransaction transaction1 = connection.BeginTransaction(); SqlTransaction transaction2 = connection.BeginTransaction(); try { // First transaction SqlCommand command1 = new SqlCommand("UPDATE Customers SET Balance = Balance - 100", connection, transaction1); command1.ExecuteNonQuery(); transaction1.Commit(); // Advanced ADO.NET Questions
Real-world example (ShopNest)
Placing an order updates stock and inserts the order row in one SqlTransaction—either both succeed or both roll back.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png