title: Will a transaction always commit (making sure file is imported only once)?
body: <p>The question I ask needs some introduction. I have an application that imports small files and e-mails into its own SQL Server database from a folder every 5 minutes. It is of great importance that</p>
  
  <ol>
  <li>each file must be imported</li>
  <li>each file must only be imported once</li>
  </ol>
  
  <p>Now part 1 is not a big deal. Part 2 however raises some concerns. If the file cannot be deleted after being successfully imported (for example due to lack of access rights), and the next time my application looks at the folder the file will be imported again and again, until someone fixes the access rights problem.</p>
  
  <p>Thus I was wondering if the following approach would work safely, without data loss:</p>
  
  <ol>
  <li>start a transaction</li>
  <li>import the file into the DB</li>
  <li>delete the file from the folder</li>
  <li>commit the transaction (or rollback if there was an error)</li>
  </ol>
  
  <p>This is the point where I arrived to the title of the question: <strong>will the last commit step always succeed if prior steps did not throw an exception?</strong> Am I safe to delete the file before the commit, without risking losing the file? What if SQL Server is shut down during transaction? Or shall I delete the record from the database if file deletion failed?</p>