High severityconfiguration
Power BI Refresh Error:
5120
What does this error mean?
SQL Server cannot open or attach a database file — the file path is wrong, the file is missing, or SQL Server lacks permission to access it.
Common causes
- 1The .mdf or .ldf file path specified in ATTACH DATABASE does not exist or is misspelled
- 2The SQL Server service account does not have read/write permission on the file or the directory
- 3The file is locked by another process (another SQL Server instance, a backup job, or anti-virus)
How to fix it
- 1Step 1: Verify the file exists at the exact path: use File Explorer or: xp_fileexist 'C:\path\to\file.mdf'; — returns 1 if found.
- 2Step 2: Grant the SQL Server service account permission on the file and its parent directory: right-click the file → Properties → Security → add the SQL Server service account (e.g. NT SERVICE\MSSQLSERVER) with Full Control.
- 3Step 3: Check if the file is locked: in Process Explorer or with: SELECT * FROM sys.dm_os_wait_stats WHERE wait_type LIKE '%FILE%'; — if locked by another SQL Server instance, detach it first.
Frequently asked questions
Official documentation: https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-5120-database-engine-error