Remove row from database and directory on disk in one transaction [duplicate]

痴心易碎 提交于 2019-12-11 05:29:55

问题


Possible Duplicate:
Deleting files and corresponding entries from database

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/13033870/remove-row-from-database-and-directory-on-disk-in-one-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!