SSIS - The process cannot access the file because it is being used by another process

Viewed 42579

I have following Dataflow:

enter image description here

Control:

enter image description here

I just wanted to copy all the data from flatfiles in sourcefolder to sql database and after copying move those files to folder named Done.

But when i run this, i get error:

[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.".

Data gets copied to sqlserver , but file does not moves.

My process tab is as follows:

enter image description here

10 Answers

My solution:

  1. Go to Task Manager
  2. Details Tab. enter image description here
  3. Locate the process “DtsDebugHost.exe“.
  4. Kill this process. There might be multiple instances of this process. Kill all of them.
  5. Reexecute SSIS package

Add a script task executing below mentioned lines, before doing file operation:

Public Sub Main()

Dim procList() As Process = Process.GetProcesses()

Dim k As Integer

For k = 0 To procList.GetUpperBound(0) Step k + 1

If procList(k).ProcessName = "EXCEL" Then

procList(k).Close()

procList(k).Dispose()

End If

Next

GC.Collect()

GC.WaitForPendingFinalizers()

Dts.TaskResult = ScriptResults.Success

End Sub

You can easily "File System Task" component.

Image of Your Control Flow:

You can pass the name of your current file as a parameter to "File System Task" component

Image for File System Task Setting

I tested it myself and everything was ok!

Related