How to write a transaction to cover Moving a file and Inserting record in database?
asp.net, c#
Solution
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();
}
Problem
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(); } ```