Search code examples
excelssisvisual-studio-2019sql-server-2019

Import or skip locked excel file while loading a lot of xlsx files on shared drive


I am importing the contents of a bunch of excel files into a database. Basically importing all the files in a folder on a shared network-drive. I am using a for each file enumerator for this. Works like a charm. However, if one of those files is opened by another user (which could be anytime) my procedure fails. The procedure fails on the Excel source connection in the dataflow. Default Excel source connector.

I would like to either

  • just skip the file, continue with the next file (next iteration of loop) and try to import it on the next run
  • somehow open the file readonly (like excel itself allows me to do)

Preferably no script task solutions (not much scripting knowledge available in team) but if it has to be scripting, so be it. I can comment it to biblically proportions so the team will understand.


Solution

  • From my comment was asked to post this as solution:

    You would have to use C# script task and do something like here: stackoverflow.com/a/937558/1459036 Then build something else in to mark it as locked as you are looping so you can go back and do that one again.