A SQL deadlock occurs when an Excel refresh and another database transaction hold locks on separate resources and each attempts to acquire a lock on the resource held by the other. Because neither process can proceed, the SQL Server Database Engine terminates one session as the “deadlock victim” (typically returning Error 1205) to allow the other to complete. In Excel, this manifests as an aborted data refresh, an OLE DB/ODBC execution failure, or an unresponsive connection window.
How to resolve deadlocks between Excel and SQL Server
To resolve deadlocks between Excel and SQL Server, change the Excel connection’s transaction isolation level to Read Committed Snapshot Isolation (RCSI) or append the
WITH (NOLOCK)table hint to the underlying SQL query. This prevents Excel’s read operations from acquiring shared locks that block, or are blocked by, concurrent database read-write transactions.
Understanding the Excel-SQL Deadlock Cycle
When Excel queries SQL Server through Power Query, OLE DB, or Microsoft Query, it defaults to the database’s default transaction isolation level—most commonly READ COMMITTED. Under standard locking mechanisms, a SELECT statement acquires shared (S) locks on rows, pages, or entire tables. These shared locks prevent concurrent database transactions from modifying (X lock) those same data pages until Excel finishes streaming the entire dataset into memory.
When an automated process, ERP system, or transactional application writes to the tables that an analyst refreshes in Excel, a collision occurs:
- Process A (the database application) updates Row 1 and holds an exclusive (
X) lock, preparing to update Row 2. - Process B (Excel’s query) scans the table, successfully reads Row 2, and places a shared (
S) lock on it. - Process A attempts to write to Row 2 but is forced to wait for Excel to release its shared lock.
- Process B attempts to read Row 1 to continue streaming records into Excel, but it encounters Process A’s exclusive lock.
Neither process can yield. SQL Server’s lock monitor thread detects the cyclical dependency, selects the connection with the lowest rollback cost (frequently the read-only Excel query), and kills it. Excel reports that the query failed or that the connection was severed by the remote host.
Immediate Fix: Implementing Non-Locking Reads
If you have permission to edit the query string in Excel, the fastest way to stop deadlocks without changing server architecture is to prevent Excel from holding shared locks.
1. Add Query Hints in Power Query or Native SQL
If your Excel workbook connects using a custom SQL statement, modify the source syntax to include the WITH (NOLOCK) hint across your data extraction tables:
SELECT
SalesOrderID,
OrderDate,
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader WITH (NOLOCK)
WHERE OrderDate >= '2024-01-01'
In Power Query’s Advanced Editor, this can be integrated directly into your Value.NativeQuery or Sql.Database call:
let
Source = Sql.Database("DatabaseServer01", "ProductionDB", [Query="SELECT * FROM Sales.Orders WITH (NOLOCK) WHERE Status = 'Active'"])
in
Source
Note on Data Integrity: WITH (NOLOCK) allows dirty reads. If a transaction rolls back while Excel reads the records, uncommitted data may appear in your spreadsheet. If reporting requires strict transactional consistency, use snapshot isolation instead.
2. Disable Background and Parallel Query Refresh
When workbooks contain multiple queries loading simultaneously, Excel issues multiple concurrent connections that can deadlock against each other or compound lock contention on the host server.
- Navigate to the Data tab in the Excel ribbon.
- Select Queries & Connections to display the side pane.
- Right-click the affected query and choose Properties.
- In the Usage tab, uncheck Enable background refresh.
- Repeat this for all dependent queries.
Disabling background refresh forces Excel to complete each extraction serially, avoiding concurrent competing transactions originating from the same workstation. For broader conflict management when orchestrating multi-table models, see Using the “Refresh All” button vs. Individual Query Refresh: Conflict resolution.
Diagnostic Steps: Identifying the Blocker
If modifying query hints does not resolve the error, determine whether Excel is competing with transactional write batches, maintenance tasks, or another analytical session.
Step 1: Trace the Deadlock Graph in SQL Server
Ask your database administrator (DBA) to inspect the Extended Events system health session (system_health), which captures deadlock graphs automatically. The XML deadlock graph identifies:
- The Victim Process ID and Owning Process ID.
- The exact SQL statement executed by each connection.
- The lock mode requested (e.g.,
RangeS-U,X,S). - The specific table, index, or page resource under contention.
If your query is terminating before the lock monitor catches the circular dependency, see Solving “Transaction (Process ID) was deadlocked on lock resources.” for dedicated steps on evaluating engine-level trace flags.
Step 2: Check for Query Folding Breaks
Power Query performs best when data transformations fold into native SQL statements executed on the database server. If an applied transformation cannot fold, Excel pulls thousands of unindexed rows across the network while holding locks on the source tables for an extended duration.
Right-click the applied steps in Power Query. If View Native Query is disabled, the transformation is happening locally inside Excel’s mashup engine. Optimize the query upstream so filtering occurs entirely inside SQL Server before Excel pulls records. For troubleshooting techniques, see Troubleshooting “Query Folding” breaks: Why your SQL is running slow in Excel.
Structural and Server-Level Solutions
When deadlocks recur across enterprise reporting workbooks, isolated client fixes are insufficient. Implement structural mitigations at the database tier.
Enable Read Committed Snapshot Isolation (RCSI)
The standard solution for high-concurrency environments combining OLTP (Online Transaction Processing) and reporting reads is enabling RCSI on the host database:
ALTER DATABASE ProductionDB
SET READ_COMMITTED_SNAPSHOT ON
WITH ROLLBACK IMMEDIATE;
Under RCSI, read operations do not acquire shared locks. Instead, queries read row versions stored in tempdb. Writers do not block readers, and readers do not block writers.
Caution: Ensure tempdb has adequate disk space and I/O throughput before enabling RCSI. If large report refreshes flood the version store, refer to Troubleshooting “TempDB” exhaustion on the server triggered by Excel refreshes.
Adjust Client-Side Command Timeouts
When lock contention stalls a query, Excel may abort prior to the deadlock detection cycle due to reaching a network transport timeout. Extending this boundary allows temporary lock chains to clear cleanly:
- Open Power Query and select the SQL Source step.
- In the formula bar, append the
CommandTimeoutparameter:Sql.Database("ServerName", "DBName", [CommandTimeout=#duration(0, 0, 15, 0)])