I want to create a file and persist some records in DB (SQL server) together in one transaction. So "creating a file and inserting records into DB" must happen both or none. I tried below code but it didn't work:
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
{ }
}
}
I've studied about Transactional NTFS (TxF), but I don't know how I can work with it and if it is helpful or not. I use SQL server 2008 R2 and windows 7/server 2008 R2.