SSIS check file is locked and wait until file is unlocked (C# Script)

Introduction

In this small blog post you will learn How to move files using SSIS Advanced File System Task and How to wait until file is unlocked using C# Script Task.

How to check if file is locked (SSIS C# Script Task)

If you want to check if file is locked in C# then below code will do the trick. But no worry if you dont know C#. ZappySys SSIS PowerPack comes with two tasks which can solve this issue without coding. You can use SSIS Advanced File System Task with Get file lock status action or Use SSIS Validation Task which has option to throw error on lock condition or you can continue by saving lock status into variable and continue without throwing error.

How to wait until file is unlocked (SSIS C# Script Task)

Now lets check real example which will first check for locked file using SSIS Validation Task and then if file is locked then wait until file is unlocked (with some timeout hardcoded in script).

If specified wait time is reached then script will throw error. Once file is unlocked SSIS Advanced File System Task will copy file to target.

SSIS - How to check if file is locked. Wait until file is unlocked (C# Code - SSIS Script Task).

SSIS – How to check if file is locked. Wait until file is unlocked (C# Code – SSIS Script Task).

SSIS Validation Task -Store file lock status into variable

SSIS Validation Task -Check if file is locked. Save status to variable or throw error.

SSIS Validation Task -Check if file is locked. Save status to variable or throw error.

SSIS Advanced File System Task – Copy, Move, Rename, Delete multiple files

SSIS Advanced File System Task. Copy, Move, Rename, Delete multiple files

SSIS Advanced File System Task. Copy, Move, Rename, Delete multiple files

SSIS C# Script Task – Check file is locked, wait until file is unlocked

Download Sample Package

Below sample will work only if you have SSIS PowerPack Installed. Download it from here it will take only 1 minute to install
Download SSIS 2012 – Sample Package (Process Locked file)

Conclusion

Processing and detecting locked files in SSIS can be tricky but using small C# script it can save you some headache. Download Advanced File System Task to try many options not available in native File System Task.

Other Keywords:
Check locked files in SSIS
How to check whether file is locked or not in SSIS
Detect locked file in SSIS
Wait until file is unlocked using C# script
How to handle file locking issue in SSIS using C# script

Posted in SSIS Advanced File System Task and tagged , , , , , .