TransactionScope, ADO.NET, and Timeouts

by Christoph Herold 31. Oktober 2006 10:58

Happy Halloween everyone!

Today I'll tell you about some problems I've been having with the TransactionScope class. Namely, I've had timeouts running out, but the application still running the nested queries until they were finished. Amazingly, the data seemed to be in the tables, although the TimeoutException was thrown.

This has now happened to me in multiple applications. But today I read an article on the System.Transactions namespace (http://msdn.microsoft.com/msdnmag/issues/06/11/DataPoints/default.aspx). There the author states, that you should open the database connection INSIDE the TransactionScope. This becomes logical, when you know that there is also a parameter you can add to the connection string named "auto-enlist" defaulting to true, that tells ADO.NET to look for an ambient transaction when connecting. So, if you open the database connection and then open a TransactionScope, the database does not seem to care about the ambient transaction.

I haven't tried yet, if this solves my problems. But since this is quite an important matter, I wonder why Microsoft does not point this out clearly. The TransactionScope may be a really great invention, but if you don't know how to use it, it causes damage instead of making things safer.

[Update]: This did not fix the problem. Instead, I built a test-app containing both a method, which first opens the database, then the TransactionScope, and a method doing it the other way around. Both methods have the same result. And that is VERY disappointing: The changes to the database made during the Transaction's non-timeout-ed period are rolled back, all changes AFTER the transaction times out are committed. I've written a post in the MSDN-Forum concerning Transactions Programming (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876150&SiteID=1). Let's see what they come up with.

Tags: ,

Development

Month List

Impressum (for the Germans)

Christoph Herold

Dieses Weblog wird bereitgestellt und verwaltet durch

Christoph Herold
Ignaz-Semmelweis-Str. 37
41540 Dormagen
Deutschland

Sie erreichen mich unter christoph.herold@coeamyd.net.