2

I have an SSIS package where I am generating a file and sending it to a user, that works all well. however, they want the date in the file name, and I don't want to have a bunch of old daily files sitting in my directory, so I try to delete the file after sending (all of this is done is a script task).

System.IO.File.Delete(DestinationName);

Now, the problem is, I get an error saying it can't delete because the file is in use by another process (the sending of the email) so I thought to make it wait a bit:

//wait a minute before deleting 
System.Threading.Thread.Sleep(60000);
System.IO.File.Delete(DestinationName);

By this time I have recieved the email, however, the process is still holding on to the file. How do I get the email to let go? Do i need to put this in its own Script Task?

Thanks

Limey
  • 2,642
  • 6
  • 37
  • 62
  • http://stackoverflow.com/questions/1304/how-to-check-for-file-lock – billinkc Nov 26 '13 at 21:52
  • 1
    quick fix could be to delete the file from outside of the ssis package. F.i: Define a seperate step in the job starting your package. Your package will be done so the file handle will most likely be gone. – Steffe Nov 29 '13 at 11:01
  • My current solution is to wait till the next day to delete the file in my SSIS package while i generate a new one to email. – Limey Dec 02 '13 at 17:05
  • Also Found that a using took care of the issue as well. I did try it before, but didn't work the first time, might of been some other error i didn't notice – Limey Dec 02 '13 at 19:24
  • Could you use a file system task to do the deletion instead of the script? – CustodianOfCode Mar 04 '15 at 05:18

0 Answers0