从磁盘数据库和目录在一个事务中删除一行 [英] Remove row from database and directory on disk in one transaction

查看:175
本文介绍了从磁盘数据库和目录在一个事务中删除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1739444/deleting-files-and-corresponding-entries-from-database\">Deleting从数据库文件以及相应的条目

Possible Duplicate:
Deleting files and corresponding entries from database

我正在写一个ASP.NET应用程序。我在物理路径的数据库中的一行到磁盘上的文件夹中。我想删除的行或删除该目录在一个事务中。即确保两个被删除或两者都没有。

I'm writing an ASP.NET application. I have a row in a database with physical path to a folder on disk. I want to delete the row and remove the directory in one transaction. I.e. make sure both are deleted or both are not.

我使用实体框架与数据库进行通信。

I'm using Entity Framework to communicate with the database.

要删除的文件夹中包含的图像,这可以通过一个网站用户观看。我怕我可以尝试在目前的图像传输到IIS用户删除该文件夹。

The folder to be removed contains images, which may be viewed by a web-site user. I'm afraid I could try to delete the folder at the moment an image is transferred to a user by IIS.

推荐答案

有关这一点,你需要使用的事务范围,如果​​你的服务器是Windows 2008 R2或2012年将工作,因为该交易将超过SQL和的 NTFS 。确保分布式事务处理协调器窗口服务处于运行状态。

For this you need to use Transaction Scope, if your server is Windows 2008 R2 or 2012 it will work because the Transaction will be over SQL and NTFS. Make sure the Distributed Transaction Coordinator windows service is in running state.

这篇关于从磁盘数据库和目录在一个事务中删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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