What is the role of the TransactionScope class in ADO.NET?
The TransactionScope class in ADO.NET is used to handle distributed transactions
across multiple data sources (e.g., SQL Server and other databases). It simplifies
transaction management by automatically handling the commit and rollback of transactions
across multiple resources.
Example:
using (TransactionScope scope = new TransactionScope())
SqlConnection connection1 = new
SqlConnection(connectionString1);
SqlConnection connection2 = new
SqlConnection(connectionString2);
connection1.Open();
connection2.Open();
// Execute commands on both connections
scope.Complete(); // Commit the transaction if everything is
successful
Follow: