Welcome to MSDN Blogs Sign in | Join | Help

Why and When to use transactions?

Many people ask - do I need transactions? Why do I need them? When to use them?

The answer is simple: use them all the time, unless you have a very good reason not to (for instance, don't use atomic transactions for "long running activities" between businesses). The default should always be yes. You are in doubt? - use transactions.

Why are transactions beneficial? They help you deal with crashes, failures, data consistency, error handling, they help you write simpler code etc. And the list of benefits will continue to grow with time.

Don't think in terms of transactions only when you talk to two or more databases. Starting with technologies like LTM, transactions are made available to be used for any multi-action operation. "X = A+B; Y = C*D;" can be transactional or atomic, as some prefer to name it, and can be seen as a single unit of work.

That is also why support for transactions is available almost everywhere. In database systems, in COM+, in ASP.NET, in .Net Framework with System.Transactions and EntepriseServices, in Indigo, in Biztalk etc

You might be saying now: "but my friend X doesn't use transactions - why it is important that I use them?". It is mostly a problem on the education side. The industry didn't talk a lot about transactions and their usage until recently. The original scope of transactions was limited to database scenarios. But technologies around transactions evolved and continue to evolve, in terms on capabilities, ease of use, flexibility, performance etc.

We used to talk about composable objects (as in OOP). We currently talk a lot about composable web services (as in SOA). The technologies are already here to start talking about composable atomic units of work.

How about the future? One avenue is STM or "software transactional memory". Maybe another one is transactional support at hardware level.

Published Tuesday, October 04, 2005 1:07 AM by florinlazar

Comments

# re: Why and When to use transactions?

Wednesday, October 05, 2005 2:00 PM by GK
Informative blog - keep up the good work. I'd like to know if Indigo supports transactions with snapshot isolation. Snapshot isolation is new to SQL Server 2005 (I believe Oracle already has it in 10g) and I'd like to know if Indigo supports this level of isolation.

# re: Why and When to use transactions?

Friday, October 07, 2005 3:15 AM by florinlazar
To GK: Indigo transaction support is based on System.Transactions. Since System.Transactions supports Snapshot (see http://msdn2.microsoft.com/en-us/library/248t96aw), Indigo will do the same.

# re: Why and When to use transactions?

Wednesday, October 12, 2005 1:25 PM by GK
Thanks for the confirmation. Does it hold true for Oracle as well?

# Why and When to use transactions?

Tuesday, November 27, 2007 7:48 PM by Why and When to use transactions?

# re: Why and When to use transactions?

Thursday, January 10, 2008 12:02 PM by florinlazar

to GK:

System.Transactions will pass the configured isolation level to any provider, including Orcle's. The provider has the option to interpret the isolation level and take it into account.

Anonymous comments are disabled
 
Page view tracker