开发者

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 c开发者_开发知识库omplex Entity in the database with all its relation.

    public void InsertEntity(Entity entity)
    {
       using(TransactionScope scope = new TransactionScope())
       {
           EntityDao.Create(entity);
       }    
    }
    
  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 http://code.google.com/p/softwareishardwork/ 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜