What are transactions in C#? (.NET interview questions with answers)
Transaction is a set of operations that should be considered as one unit.
Either every operations will executes successfully or none will. It should not end up in middle.
Best Example for transaction is money transactions in banks where X amount will be transferred from Account A to Account B. Steps are
1. Deduct Amount X from Account A
2. Add Amount X to Account B.
Let say after step 1 and before step 2 power failure happen. In that case step 1 will also get rolled back because both the steps together are considered as one Transaction
So how to do we implement a transaction in .NET?
To implement transactions we can use the transaction scope object as shown in the below code.
How do we implement transactions in SQL Server stored procedure?
To implement transaction in SQL Server we need use "Begin transaction" and "Commit" transaction as shown in the below code.
How do we implement transaction using ADO.NET ?
Connection object of ADO.NET has a transaction object we can use that.
Do miss the below SQL Server interview question video :- Can views be updated ?