如何写一个交易涵盖移动一个文件,并在数据库中插入记录? [英] How to write a transaction to cover Moving a file and Inserting record in database?
本文介绍了如何写一个交易涵盖移动一个文件,并在数据库中插入记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个事务复制一个文件,然后在数据库中插入一条记录。
类似下面的语句,但交易不包括复制文件。
有什么解决办法?
使用(TransactionScope的scope1 =新的TransactionScope())
{
//复制文件
fileMgr.Move(srcFileName,destFileName); //插入数据库记录
dbMgr.ExecuteNonQuery(insertSql); scope1.Complete();
}
解决方案
尝试使用 .NET事务性文件管理器
这个库可以让你在这样的交易换文件系统操作:
//裹在同一事务的文件副本和一个数据库插入
TxFileManager fileMgr =新TxFileManager();
使用(TransactionScope的scope1 =新的TransactionScope())
{
//复制文件
fileMgr.Copy(srcFileName,destFileName); //插入数据库记录
dbMgr.ExecuteNonQuery(insertSql); scope1.Complete();
}
I want to have a transaction for copying a file and then inserting a record in database. something like below statement, but transaction doesn't cover copying file. What's the solution?
using (TransactionScope scope1 = new TransactionScope())
{
// Copy a file
fileMgr.Move(srcFileName, destFileName);
// Insert a database record
dbMgr.ExecuteNonQuery(insertSql);
scope1.Complete();
}
解决方案
Try to use .NET Transactional File Manager
This library allows you to wrap file system operations in transactions like this:
// Wrap a file copy and a database insert in the same transaction
TxFileManager fileMgr = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
{
// Copy a file
fileMgr.Copy(srcFileName, destFileName);
// Insert a database record
dbMgr.ExecuteNonQuery(insertSql);
scope1.Complete();
}
这篇关于如何写一个交易涵盖移动一个文件,并在数据库中插入记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文