SSIS - The process cannot access the file because

2020-04-04 04:54发布

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

8条回答
够拽才男人
2楼-- · 2020-04-04 05:06

If the messages cites your ".ispac" file, you have an unclosed debug. Enter Task Manager and close the Debug Host.

查看更多
相关推荐>>
3楼-- · 2020-04-04 05:06

If you are using an Excel connection, use the below code (C#) in a Script task to close all Excel processes, before you attempt to move/rename the file.

System.Diagnostics.Process[] proc=System.Diagnostics.Process.GetProcessesByName("Excel");
foreach (System.Diagnostics.Process p in proc)
{
    if (!string.IsNullOrEmpty(p.ProcessName))
    {
        try
        {
            p.Kill();
        }
        catch { }
    }
}
查看更多
老娘就宠你
4楼-- · 2020-04-04 05:10

I found this link by accident and posting this to help others that get here as well.

When using a Script task make sure you drop connection with Close() or use connection inside a USING().

The connection is held after the task is complete and until the whole package is complete unless you do either of the above.

查看更多
趁早两清
5楼-- · 2020-04-04 05:15

for me this error has nothing to do with SSIS and occurred after end tasking not responding BIDS

one of my excel files was get locked by BIDS debugger(DtsDebugHost.exe) which closing BIDS does not helps.

finally using http://filehippo.com/download_unlocker/ shows me actual locker and also simply remove it.

please note that BIDS needs to be restarted after unlocking DtsDebugHost.exe

查看更多
孤傲高冷的网名
6楼-- · 2020-04-04 05:19

This may be too obvious, but have you tried inserting a short delay to give the dataflow time to let go of the file? For example, insert an Execute SQL Task with contents like:

-- Wait for 1 second
WAITFOR DELAY '00:00:01'

Alternatively, you could handle the Failure Path and retry, perhaps after a delay.

查看更多
forever°为你锁心
7楼-- · 2020-04-04 05:22

I use this function in tandem with a wait routine:

public bool IsFileLocked(string filePath)
{
    try
    {
        //Open the file exclusively
        using (File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None)) { }
    }
    catch (IOException e)
    {
        var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1);
        return errorCode == 32 || errorCode == 33;
    }

    return false;
}
查看更多
登录 后发表回答