File System Task > Move Files > Error - Process cannot access the file because its being used by another process

  • Hi,

    I have 2 foreach loop containers within my control flow:

    The first foreach loop container loops through a directory and loads files into a table

    The second foreach loop container loops through the same directory and moves the files to an archive directory.

    When executing the package I receive the following error message:

    [File System Task] Error: An error occurred with the following error message: "The process cannot access the file because it is being used by another process".

    Any suggestions would be greatly appreciated.

    Regards,

    Chris

  • Why not use a single Foreach loop to do the entire load/archive process?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Hi Phil,

    I've already tried this and receive the same error

    Chris

  • Full details of package as follows:

    Loop 1 (looks for Excel file)

    loop2 (looks for Excel sheet using ado.net schema rowset)

    DFT

    End loop 1

    End loop 2

    |

    |

    \/

    Loop 3

    Move file

    End Loop3

    Could the ado.net schema rowset, be causing issues?

    Chris

  • It might be possible that the file download on your source directory is not complete and at the same instance you are trying to move the file. 2 Processes are accessing the same resource.

    Create an onfailure event and loop through the rest of the files in the folder or write a script task to Open each file (catch an exception if the file cannot be open) before moving.

  • Since this took me MANY HOURS to solve, I'm posting my solution for others. And it was sooo simple...

    Place a copy of your Excel File in another folder and name it "template.xlsx". Have your Schema connection point to this copy. The actual Excel file will no longer be kept locked by the ForEach Worksheet Schema loop!

  • Thank you sooo much. After many days - this is the only solution that worked.:-)

  • Rather than maintain two copies of the same file, Import then move the file all in one loop.

    ----------------------------------------------------

  • Well, i saw the same issue & there is a property on Excel connection manger "RetainSameConnection". If you set this to "False" , Viola, the error disappears!

  • Well, i saw the same issue & there is a property on Excel connection manger "RetainSameConnection". If you set this to "False" , Viola, the error disappears!

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply