metricsign
Start free
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

  1. 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.
  2. 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.
  3. 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

Why does error 5120 happen even when the file clearly exists?

The most common cause is a permission mismatch — the file exists but the SQL Server service account cannot read it. This often happens when files are copied from another machine and the original NTFS ACL is inherited. Fix by explicitly granting the service account permission.

How do I find the SQL Server service account name?

Open SQL Server Configuration Manager → SQL Server Services → right-click your SQL Server instance → Properties → Log On tab. The account name is shown there (e.g. NT SERVICE\MSSQLSERVER or a domain account).

Can error 5120 occur when moving a database to a new drive?

Yes — after moving .mdf/.ldf files to a new drive, the new location may not have the SQL Server service account in its ACL. Grant Full Control on the new directory before attempting to attach or start the database.

Official documentation: https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-5120-database-engine-error

Other configuration errors