Strange behaviour of code inside TransactionScope?

We are facing a very complex issue in our production application.

  1. We have a WCF method which creates a complex Entity in the database with all its relation.

    public void InsertEntity(Entity entity)
       using(TransactionScope scope = new TransactionScope())
  2. EntityDao.Create(entity) method is very complex and has huge pieces of logic. During the entire process of creation it creates several child entities and also have several queries to database.

  3. During the entire WCF request of entity creation usually Connection is maintained in a ThreadStatic variable and reused by the DAOs. Although some of the queries in DAO described in step 2 uses a new connection and closes it after use.

Overall we have seen that the above process behaviour is erratic. Some of the queries in the inner DAO does not even return actual data from the database? The same query when run to the actaul data store gives correct result.

What can be possible reason of this behaviour?


ThreadStatic is not recommended. Use CallContext instead. I have code at which demos the correct way to handle connections in a manner you describe (tested in severe high performance scenarios). Try a test case using this code.

Need Your Help

configure autoMapper.Mapping once in application automapper

is there any way to map 2 Models once in my application ( Mapper.CreateMap()) for example in global.asax and then wherever necessary just call Mapper.Map() in codes ?

Call EditText value in different file class java Android

java android xml onclicklistener

I'm learning to use the external class. This project is just an example. I have a class that extends Activity and in this class I want to access my Login button. And the Login Button will run the