如何与QUOT;交易"一IO操作和数据库执行? [英] How to "transaction" a IO operation and a database execution?

查看:175
本文介绍了如何与QUOT;交易"一IO操作和数据库执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含处理器正在运行的服务,它做两件事情:

I have service that contains a processor running, and it do two things:

1- Create a file in a directory.
2- Set your own status to "Processed".



不过,当服务在处理过程中准确地停了下来,在目录中创建的文件但是,这个过程没有最终确定,如:

But, when the service is stopped exactly in the middle of processing, the file is created in the directory but, the process is not finalized, like this:

  1- Create a file in a directory.
   -----SERVICE STOPPED-----
  2- Set your own status to "Processed".



我需要的方式与数据库命令,如何做到这一点办理的IO操作?

I need a way to transact the IO operations with the database commands, how to do this?

修改 - 重要

问题是创建该文件被其他应用程序捕获,所以文件需要才能真正创建如果命令成功执行。因为如果文件被创建并在另一个应用程序抓住他,并发生数据库错误后,要继续这个问题。

The problem is that the file created is captured by another application, so the file needs to be really created only if the commands are executed successfully. Because if the file be created and the another application capture him, and after an database error occurs, the problem to be continued.

OBS:我使用C#开发

OBS: I'm using c# to develop.

推荐答案

您可以使用事务性NTFS(TxF的)。这提供了以执行完全原子的,一致的,孤立的,耐用的文件操作操作的能力。

You can use Transactional NTFS (TxF). This provides the ability to perform actions that are fully atomic, consistent, isolated, and durable for file operations.

可以intergrated与大量其它事务性技术的工​​作。由于TxF的采用了全新的内核事务管理器(KTM)的特点,而且由于新的KTM可以直接与微软分布式事务处理协调器(DTC)的工作。

It can be intergrated to work with a large number of other transactional technologies. Because TxF uses the new Kernel Transaction Manager (KTM) features, and because the new KTM can work directly with the Microsoft® Distributed Transaction Coordinator (DTC).

任何技术可以与DTC工作作为一种事务协调可以在单个事务中使用的事务处理的文件操作。这意味着您现在可以通过OleTransactionProtocol,甚至交易MSMQ操作争取通过WS-AtomicTransaction的,Windows通信基础服务相同的事务中的SQL操作,Web服务调用内部事务文件操作。

Any technology that can work with DTC as a transaction coordinator can use transacted file operations within a single transaction. This means that you can now enlist transacted file operations within the same transaction as SQL operations, Web service calls via WS-AtomicTransaction, Windows Communication Foundation services via the OleTransactionProtocol, or even transacted MSMQ operations.

文件和数据库原子事务的一个例子:使用

An example of file and database atomic transaction:

using (connectionDb)
{
    connectionDb.Open();
    using (var ts = new System.Transactions.TransactionScope())
    {
        try
        {
            File.Copy(sourceFileName, destFileName, overwrite);
            connectionDb.ExecuteNonQuery();
            ts.Complete();
        }
        catch (Exception)
        {
            throw;
        }
        finally
        { }
    }
}

有关详情请参阅以下链接:

See the following links for more information:

TxF的Codeplex上

参考MSDN

注意:请记住DTC配备了一个沉重的性能损失。

Note: Remember DTC comes with a heavy performance penalty.

这篇关于如何与QUOT;交易"一IO操作和数据库执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆