请问TransactionScope是不是只是对数据库操作的事务处理?
例如如下代码:
petshop4.0中OrderProcessor 
 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tsTimeout)) {
                    // Receive the orders from the queue
                    for (int j = 0; j < batchSize; j++) {                        try {
                            //only receive more queued orders if there is enough time
                            if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds) {
                                queueOrders.Add(order.ReceiveFromQueue(queueTimeout));
                            }
                            else {
                                j = batchSize;   // exit loop
                            }                            //update elapsed time
                            elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds - datetimeStarting.TotalSeconds;
                        }
                        catch (TimeoutException) {                            //exit loop because no more messages are waiting
                            j = batchSize;
                        }
                    }                    //process the queued orders
                    for (int k = 0; k < queueOrders.Count; k++) {
                        order.Insert((OrderInfo)queueOrders[k]);
                        processedItems++;
                        totalOrdersProcessed++;
                    }                    //batch complete or MSMQ receive timed out
                    ts.Complete();
                }
这里的事务处理中对queueOrders.Add(order.ReceiveFromQueue(queueTimeout));这句话起作用吗?这句代码是对队列的操作并不是对数据库的操作,但是在事务处理里面。

解决方案 »

  1.   

    那当程序a和程序b都连接同一个数据库,此时,程序a有TransactionScope的事务处理,程序b没有事务处理,当程序a的事物处理没有提交时候,程序b能对该数据库进行插入或者更新操作码?
      

  2.   

    TransactionScope
      

  3.   


    DML操作之锁操作的表,不锁数据库的。如你上面所说,那当程序a和程序b都连接同一个数据库,程序a进行DML操作并且没有提交,此时程序b应该还是能进行DML操作的吧,只是需要等待程序a的操作结束(commit 或 rollback)。
      

  4.   

    并发的操作对数据库不影响啊,否则你进行一个百万级的数据统计,别人就不能用数据库了?
    所以只对你操作的表有影响。
    并且影响取决于你设置的  事务等级。默认是Srexxx..什么的,就是只能读取,不能修改,不能添加。
    TransactionScope是隐式事务,是System.Transaction下的一个类,比传统的ADO.NET事务的优点就在于
    1.创建方便,管理方便,耗费资源少。它是由LTM自动管理的。
    2.可以扩展到分布式事务。楼主你用TransactionScope,他有一个作用域,就在这个using块中,只有事务的全体对象和资源都成功Commit(),才会成功,否则自动Rollback()