C#: ADO.NET Transactions

Please see my other C# articles.

Ensuring data-concurrency.

When a feature requires an atomic action, ADO.NET transactions easily ensure data concurrency while performing writes against the database.
For example, let’s say two separate db writes are needed, each of which executes a stored procedure.
Should errors occur, it’s essential that both writes are rolled-back before any changes are committed to the db. Conversely, if both actions are free from error, then both changes should be committed simultaneously.
In the example below, you will see code that illustrates the previous principles.
First, the’re the function implementing transactions and calling two separate functions.
Below that are the two functions executing sprocs, each of which is contained within a transaction so that if it should fail, it and the other changes would automatically get rolled back, preserving data concurrency.
The main function which implements transactions. Within that block are the two functions that are called leveraging Generics below.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s