为什么使用 TransactionScope 和 MSDTC 的 VS 数据库单元测试失败?
然后,我们将单元测试指向通用数据库服务器,并在运行单元测试的计算机上设置 MSDTC,该计算机一切正常。
现在,我们已经设置了一台新机器,它将针对相同的公共数据库运行单元测试。 单元测试没有在这台机器上运行,我们得到以下错误:
System.Transactions.TransactionException:事务已隐式或显式提交或中止。
MSDTC 设置与正在运行的设置完全相同,我们逐屏进行了比较。
以前有人经历过这样的事情吗? 或者有任何指示我们可以在哪里寻找可能导致此问题的线索吗?
我们检查了Windows版本和服务包、防火墙选项、msdtc选项、VS版本和服务包。
We have some unit tests running against a SQL server 2000 database using the DatabaseTestFixture class which uses a TransactionScope that is not committed and therefore all changes are rolled back. The tests ran against a local database with no problem.
We then pointed the unit tests at a common database server and setup MSDTC on the machine running the unit tests and all is well with that machine.
Now though we have setup a new machine which will be running the unit test also against the same common database. The unit test do not run on this machine, we get the following error:
System.Transactions.TransactionException : The transaction has already been implicitly or explicitly committed or aborted.
The MSDTC settings are exactly the same as the one that is working, we have compared screen by screen.
Has anyone experienced something like this before? Or got any pointers on where we might look for clues as to what might be causing it?
We have checked Windows versions and service packs, firewall options, msdtc options, VS versions and service packs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎与 NUnit 2.5 有关。
在此之前,以下代码运行良好:
在 2.5 中,事务范围需要使用
TransactionScopeOption.RequiresNew
进行实例化。 我认为要么它没有被正确处理,要么 NUnit 在运行测试时正在运行一些环境事务。将 SetUp 方法的第二行更改为
,它应该可以正常工作。
如果有人能够更好地解释为什么会发生这种情况,我很想听听。
This seems to be related to NUnit 2.5.
Before it, the following code worked fine:
With 2.5 the transaction scope needs to instanciated with
TransactionScopeOption.RequiresNew
. I assume that either it isn't being disposed correctly, or that NUnit has some ambient transaction running when the tests are being run.Change the second line on the SetUp method to
and it should work correctly.
If someone manages to get a better explanation as to why this happens, I'd love to hear it.
此问题可能与您使用的 Nunit 版本有关。 我在运行单元 2.5 时遇到了完全相同的问题,但当我使用 nunit 2.4.8 或 2.2 运行单元测试时,问题神秘地消失了。
请尝试这个,让我知道,这样我就可以提高我微不足道的个人资料积分!
问候
MAC
this problem is probably related to the version of Nunit you're using. I had exactly the same issue when running unit 2.5 but the problem mysteriously disappears when I run the unit tests with nunit 2.4.8 or 2.2.
Please try this any let me know so I boost my puny profile points!
Regards
MAC