了解 Windows 中的 MSDTC

发布于 2024-08-11 12:14:25 字数 508 浏览 1 评论 0原文

要在 Subsonic 中使用事务构造(如下),MSDTC 需要在 Windows 计算机上运行。正确的?

        using (TransactionScope ts = new TransactionScope())
        {
            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                // update table 1
                // update table 2

                // ts.commit here

            }
        }
  1. MS-DTC 是 Windows 系统(XP、Vista、Windows 7、服务器等)上的默认服务吗?
  2. 如果未启用,我如何确保它在应用程序的安装过程中启用?

To use transaction construct(as follows) in Subsonic, MSDTC needs to be running on Windows machine. Right?

        using (TransactionScope ts = new TransactionScope())
        {
            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                // update table 1
                // update table 2

                // ts.commit here

            }
        }
  1. Is MS-DTC a default service on Windows systems(XP, Vista, Windows 7, Servers etc)?
  2. If it is not enabled, how can I make sure it gets enabled during the installation process of my application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海蓝天 2024-08-18 12:14:25

MSDTC 应该随 Windows 一起安装。如果不是,可以使用以下命令进行安装:

msdtc -install

您可以使用 sc.exe 配置 MSDTC 服务。将服务设置为自动启动并启动服务:

sc config msdtc start= auto
sc start msdtc

请注意,您将需要管理员权限才能执行上述操作。

MSDTC should come installed with windows. If it's not it can be installed with the following command:

msdtc -install

You can configure the MSDTC service using sc.exe. Set the service to start automatically and start the service:

sc config msdtc start= auto
sc start msdtc

Note you will need administrator privilege to perform the above.

二货你真萌 2024-08-18 12:14:25

我用:

private bool InitMsdtc()
{
    System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController("MSDTC");
    if (control.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
        control.Start();
    else if (control.Status == System.ServiceProcess.ServiceControllerStatus.Paused)
        control.Continue();
    return true;
}

I use:

private bool InitMsdtc()
{
    System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController("MSDTC");
    if (control.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
        control.Start();
    else if (control.Status == System.ServiceProcess.ServiceControllerStatus.Paused)
        control.Continue();
    return true;
}
假装爱人 2024-08-18 12:14:25

如果您的 DBMS 是 SQL Server 2000 并且您使用 TransactionScope,则即使是本地事务也会创建分布式事务。然而,SQL Server 2005(可能还有 SQL Server 2008)足够聪明,可以发现不需要分布式事务。我不知道这是否仅适用于本地数据库,或者如果您的事务仅涉及单个数据库(即使它位于删除服务器上),那么情况是否如此。 http://davidhayden.com/blog/dave/archive/2005 /12/09/2615.aspx

一个提示,你可以使用批量查询来避免TransactionScope。

http://subsonicproject.com/docs/BatchQuery

BatchQuery、QueueForTransaction 和 ExecuteTransaction 将不会使用 TransactionScope(当然这取决于提供程序的实现),但选择底层数据提供程序的事务机制(在本例中为 SqlTransaction),这不需要 MSTDC。

If your DBMS is SQL Server 2000 and you use a TransactionScope a distributed transaction is created even for local Transaction. However SQL Server 2005 (and probably SQL Server 2008) are smart enough to figure out that a distributed Transaction is not needed. I don't know if that only applies to local DB's or even is true if you Transaction only involves a single DB even if it's on a remove server. http://davidhayden.com/blog/dave/archive/2005/12/09/2615.aspx

One hint, you can use a batch query to avoid the TransactionScope.

http://subsonicproject.com/docs/BatchQuery

BatchQuery, QueueForTransaction and ExecuteTransaction will not use a TransactionScope (of course that depends on the provider implementation) but choose the transaction mechanismn of the underlying data provider (SqlTransaction in this case) which won't require MSTDC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文