Tutorials ADO.NET Core Tutorial
Commit and Rollback — Complete Guide
Commit and Rollback — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.
On this page
ADO.NET Core Tutorial · Lesson 32 of 100
Commit and Rollback
Foundations ✓ → SQL & safety → Production → Projects
SQL & safety · 2 — Procs, tx, performance · ~6 min · Module 4: Transactions and Error Handling
What is this?
Commit makes changes durable; rollback restores the prior state for the transaction.
Why should you care?
ShopNest must rollback when any step in place-order fails.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
await using var tx = (SqlTransaction)await conn.BeginTransactionAsync(ct);
cmd.Transaction = tx;
await cmd.ExecuteNonQueryAsync(ct);
// await tx.CommitAsync(ct); // keep
// await tx.RollbackAsync(ct); // undo
await tx.RollbackAsync(ct);
Console.WriteLine("rolled back");
What happened?
- Only one outcome.
- After rollback, don’t reuse the same broken state blindly — start fresh.
Practice next
- Commit a demo insert.
- Rollback another.
- Verify SSMS.
- Partial try with savepoints later.
- Count @@TRANCOUNT.
Remember
Commit = keep. Rollback = undo. Always handle errors.
ShopNest safe catch
Repos always rollback on exception.
Outcome: No zombie open transactions.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!