Asp.net Oracle transaction事务出现奇怪的aotucommit自动提交现象及解决办法

出现了同样的问题 ,测试有效http://blog.csdn.net/xdpost/archive/2009/02/08/3868606.aspx

 

Asp.net Oracle 事务出现奇怪的自动提交现象及解决办法 

前几天在项目中测试人员告诉我,我的程式中有关oracle transaction的事务控制有问题,在程式执行过程中,即使回滚了数据还是能写到数据库,当时我检查了程式,可是奇怪的是我的事务控制都有ROBACK,COMMIT。于是我自己又测试了一次,惊奇的事情发生了,我发现每当从新打开项目,第一次调试时,transaction能正常回滚,可是再运行一次就有问题,后面的测试不用提交数据就写进去了。大致是这样的步骤:

step a: new oracleconnectionA,then open(strConn)

step b: oracleconnectionA.begintransaction()

step c:  todo some insert,update

step d: if c successful then commit,else rolback

step e: close oracleconnectionA

结果第一次运行,设置断点在c,刚运行完c发现数据没写进去,至到运行完e,数据才写进去,这第一次是正确的,紧接着再做同样的运行,刚运行完c,还没执行d,去数据库中查询就发现数据已经写进去了。

我还在一段程式中写了两段transaction控制进行测试,如下步骤:

step a: new oracleconnectionA,then open(strConn)

step b: oracleconnectionA.begintransaction()

step c:  todo some insert,update

step d: if c successful then commit,else rolback

step e: close oracleconnectionA

step f: new oracleconnectionB,then open(strConn)

step g: oracleconnectionB.begintransaction()

step h:  todo some insert,update

step i: if c successful then commit,else rolback

step j: close oracleconnectionA

结果发现第一次运行时a-e的过程,事务还是正常的,但一执行完h,还未执行i,本来要在i提交的数据就已经写进数据库了。在我进过很多次的修改,调试,修改,调试,查资料。。。请了很多人看,结果还是没发现问题。当时我还只是认为自己程式有问题,结果发现我们项目中所有的程式都有这种情况,因此还怀疑过DB有问题,但当我放在别人机器上测试时,却没出现问题,在我们的机器上运行别人的数据库和程式还是出现问题。因此将DB,程式的问题都排除了。目前的状况是我们团队的机器上测试都有问题,那么我不得不怀疑我们机器的oracle client是否有问题。结果还是不能解决。最后我想到是不是系统有问题了,还原系统后发现程式运行正常了,于是我们比对系统差异。终于让我发现导致该问题的原因是系统中一个漏洞导致的,http://support.microsoft.com/kb/958481

http://support.microsoft.com/kb/958483

http://support.microsoft.com/kb/958484

以上三个补丁能解决该问题,上述三个地址对该漏洞导致的异常做出了描述。其中就有这样的描述

  • AutoCommit behavior in Oracle transactions is different in the .NET Framework 2.0 SP1 from the behavior in the .NET Framework 2.0 SP2. In the .NET Framework 2.0 SP2, if an application starts a transaction, completes the transaction, and then starts a new transaction on the same connection, all the commands that are executed in the second transaction execute in auto-commit mode. The changes that are made by those commands are committed to the database even if the transaction is rolled back.
  • 这恰好是我遭遇的现象,终于给解决了。

    一般安装KB958481这个补丁就可以解决问题,不过建议大家最好把这些补丁都打上,都是针对.net framwork的漏洞出的

    原文地址:https://www.cnblogs.com/xiaoL/p/1985056.html