Subsonic 亚音速3事务

Subsonic 亚音速3事务,subsonic,Subsonic,我已按照MS网站上的概述配置DTC,以支持远程交易。我有下面的代码总是给我错误 using (TransactionScope ts = new TransactionScope()) { Category c = new Category(); c.Name = "Cat1"; c.Save(); Product p = Product.SingleOrDefault(x=>x.ProductID==1); p.Title = "new title";

我已按照MS网站上的概述配置DTC,以支持远程交易。我有下面的代码总是给我错误

using (TransactionScope ts = new TransactionScope())
{
   Category c = new Category();
   c.Name = "Cat1";
   c.Save();

   Product p = Product.SingleOrDefault(x=>x.ProductID==1);
   p.Title = "new title";
   p.Save();

   ts.Close();
 }

但是,如果我将第二块代码移出起诉块,它就可以正常工作。我要做的是将这两个代码块绑定到一个传输中。什么是雷登?谢谢,

您没有指定代码给您的错误,但我能看到的唯一错误是您没有在TransactionScope上调用Complete。请尝试以下操作:

using (TransactionScope ts = new TransactionScope())
{
   Category c = new Category();
   c.Name = "Cat1";
   c.Save();

   Product p = Product.SingleOrDefault(x=>x.ProductID==1);
   p.Title = "new title";
   p.Save();

   ts.Complete();
 }
using (TransactionScope ts = new TransactionScope())
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
   Category c = new Category();
   c.Name = "Cat1";
   c.Save();

   Product p = Product.SingleOrDefault(x=>x.ProductID==1);
   p.Title = "new title";
   p.Save();

   ts.Complete();
 }
您实际上不需要启用DTC,您可以使用SubSonic的SharedDbConnectionScope将此代码包装在事务中。请尝试以下操作:

using (TransactionScope ts = new TransactionScope())
{
   Category c = new Category();
   c.Name = "Cat1";
   c.Save();

   Product p = Product.SingleOrDefault(x=>x.ProductID==1);
   p.Title = "new title";
   p.Save();

   ts.Complete();
 }
using (TransactionScope ts = new TransactionScope())
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
   Category c = new Category();
   c.Name = "Cat1";
   c.Save();

   Product p = Product.SingleOrDefault(x=>x.ProductID==1);
   p.Title = "new title";
   p.Save();

   ts.Complete();
 }

谢谢你的回答。这是我得到的错误,实际上我有那行代码,但仍然得到了错误。System.Transactions.TransactionManager通信异常:已禁用分布式事务管理器(MSDTC)的网络访问。请使用组件服务管理工具在MSDTC的安全配置中为网络访问启用DTC确定错误消息表示DTC配置不正确。下面的答案可能会帮助您,但正如我在上面所述,您应该能够完全避免使用DTC。我实际上按照几篇文章中所述配置DTC。但是我还是犯了那个错误。因为我可以在没有第二个代码块的情况下提交事务,这意味着DTC正在工作。如果我添加了第二个代码块,我就无法找出导致冲突的原因。我昨天尝试了你的代码,它给了我无效的对象错误消息。在我看来,错误在于连接作用域使用了错误的数据集。确定。我将sharedConnectionScope更改为使用特定的连接字符串,现在可以使用了。它真的是有线的。我也不知道你们是否可以编辑亚音速网站。网站上的交易指南是错误的。也许有人可以改变它。作为一个注释,我相信对于所有具有亚音速的非MS-SQL提供程序,DTC都是必需的