This error occurs when Power Query attempts to open, transform, or load data from an external file (such as an .xlsx, .csv, .txt, or .accdb file), but the Windows operating system rejects the request because another application or background process holds an exclusive write-lock on that file. Power Query cannot read the file until that lock is released.
Fast Fix
Close any programs (including other Excel windows) that currently have the source file open. If your query references the workbook you are currently working in, do not use
File.Contents; switch the source to= Excel.CurrentWorkbook(). If the file appears closed everywhere, open Task Manager and terminate any lingering Microsoft Mashup Container processes holding the handle.
Diagnostic Snapshot
| Property | Details |
|---|---|
| System Error Code | Win32 Error 0x80070020 (ERROR_SHARING_VIOLATION) |
| Power Query Message | The process cannot access the file '[Path]' because it is being used by another process. |
| Common Scenarios | 1. Self-referencing workbooks.<br>2. Cloud sync locking (OneDrive / SharePoint).<br>3. Antivirus or Windows Search indexing scanning the file.<br>4. Multiple queries simultaneously accessing an exclusive-lock format (like Access .accdb). |
Why the File-Locking Conflict Occurs
Windows uses file-sharing modes to protect data integrity. When a program opens a file with exclusive access or pending write operations, Windows sets a share lock that stops all other processes from accessing it.
In Power Query, this conflict usually happens in one of four ways:
[Target Data File: data.csv]
▲
├── [App 1: OneDrive Sync Engine] --> Holds exclusive read/write lock
└── [App 2: Power Query Engine] --> Attempts read -> SHARING VIOLATION
- Self-Referencing Query Loop: You opened
Report.xlsxand built a Power Query step that reads data fromC:\Files\Report.xlsxusingFile.Contents. Because Excel already hasReport.xlsxopen in write mode, Power Query cannot open a second read stream to the same path. - Sync Client Locks: OneDrive, SharePoint, or third-party backup clients briefly lock files while uploading changes to the cloud. If Excel refreshes during that window, the access request fails.
- Orphaned Mashup Containers: Power Query offloads heavy processing to background processes named
Microsoft.Mashup.Container.*.exe. If a previous refresh was canceled or crashed, the container process may stay running in the background and hold onto the file handle. - Antivirus or Indexer Scans: Real-time endpoint security software often locks newly modified CSV or Excel files to scan them before releasing them to the OS.
Step-by-Step Resolution
Step 1: Resolve Self-Referencing Query Loops
If your query reads data from a sheet or table inside the active workbook:
- Open Power Query Editor.
- Select the failing query and click the Source step in the Applied Steps pane.
- Look at the formula bar.
- If it looks like this:And you are currently working inside
MonthlySales.xlsx, the file is locking itself.Source = Excel.Workbook(File.Contents("C:\Users\Name\Documents\MonthlySales.xlsx")) - Change the source line to reference the internal workbook cache instead:
Source = Excel.CurrentWorkbook() - Expand the content table for your specific Excel Table or Named Range.
Using Excel.CurrentWorkbook() reads directly from the memory model of the active file, avoiding disk-level file operations entirely.
Step 2: Terminate Orphaned Mashup Container Processes
If the source file is closed but Excel still claims it is in use, an orphaned Power Query background worker is likely holding the file lock.
- Save your work and close all open Excel windows.
- Press
Ctrl + Shift + Escto open Task Manager. - Go to the Details tab.
- Sort by the Name column and search for:
Microsoft.Mashup.Container.NetFX45.exeMicrosoft.Mashup.Container.Loader.exeEXCEL.EXE
- Select any running instances of these processes and click End Task.
- Relaunch Excel and refresh your query.
Task Manager -> Details Tab
├── EXCEL.EXE [End Task]
├── Microsoft.Mashup.Container.NetFX45.exe [End Task]
└── Microsoft.Mashup.Container.Loader.exe [End Task]
Step 3: Address Cloud Sync Conflicts (OneDrive / SharePoint)
If your source files are stored in a synchronized OneDrive or SharePoint folder, file access conflicts frequently occur during background uploads.
Immediate Workaround:
- Click the OneDrive cloud icon in the Windows system tray.
- Click the gear icon (Settings) and select Pause syncing > 2 hours.
- Return to Excel and click Data > Refresh All.
- Once the refresh completes, resume sync.
Permanent Architectural Fix:
Do not connect to cloud-backed files using local file paths (e.g., C:\Users\Username\OneDrive - Org\file.xlsx). Instead, use the native web URL:
- Open the source file in Excel on the web or desktop.
- Go to File > Info and click Copy path.
- In your destination workbook, go to Data > Get Data > From Other Sources > From Web.
- Paste the URL, and remove
?web=1from the end of the string. - Authenticate with your Organizational account.
This routes queries through the SharePoint REST API rather than local disk handles, eliminating local file-sharing locks completely.
For more details on sync locks across OneDrive folders, see OneDrive “File in Use” Error (Even when the file is closed).
Step 4: Identify the Locking Process Using Resource Monitor
If the file is locked and you cannot identify what application is holding it:
- Press
Win + R, typeresmon.exe, and press Enter to open Resource Monitor. - Click on the CPU tab.
- In the Associated Handles section, click the search box.
- Type the name of the locked file (e.g.,
SalesData.csv). - Resource Monitor will list the exact Process ID (PID) and application name holding the open handle (e.g., a backup utility, antivirus agent, or an external script).
- Right-click the offending process and select End Process.
[Resource Monitor]
└── CPU Tab
└── Associated Handles
└── Search: "SalesData.csv"
└── Process: SecurityScanner.exe (PID: 4328) -> [End Process]
If lock conflicts recur when opening or writing shared workbooks across network drives, see Troubleshooting “The workbook is currently in use” during Data Refresh. If OneDrive continuously triggers sync loops due to open files, refer to How to Fix “Items can’t be synced because they are open” Loop.