When programming with c# and SQLServer, you will come into a situation where you need to execute more than one SQL statements, and ensure all commands executed successfully. If one fails, then the entire process should be aborted and moved to the initial stage.
In this scenario we need to make use of transactions. Transactions can be written inside a stored procedure or it can be written inside a C# program. ADO.NET comes with a SQLTransaction class, which can be used for this. This post explains transactions with working example.
We use pubs database for the examples. Executing following scripts will create two tables, Table1 and Table2. (more…)
