metricsign
Start free
Medium severityauthentication

Power BI Refresh Error:
15023

What does this error mean?

A CREATE USER or sp_adduser statement failed because a user or role with that name already exists in the target database.

Common causes

  • 1Restoring a database backup to a new server — the database user exists in the backup but the server login SID does not match (orphaned user)
  • 2Running a deployment script twice — the CREATE USER statement was not made idempotent
  • 3A migration script attempts to create a user that was manually created beforehand

How to fix it

  1. 1Step 1: Check if the user is orphaned (exists in DB but has no matching server login): USE [yourdb]; EXEC sp_change_users_login 'Report';
  2. 2Step 2: Re-map the orphaned user to the existing server login: USE [yourdb]; ALTER USER [username] WITH LOGIN = [loginname];
  3. 3Step 3: If the user is not orphaned and you just need an idempotent script, wrap in a check: IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = 'username') CREATE USER [username] FOR LOGIN [loginname];

Frequently asked questions

What is an orphaned user in SQL Server?

An orphaned user is a database user whose SID does not match any server login. This happens when a database is restored to a different server. Detect them with: EXEC sp_change_users_login 'Report'; and fix with ALTER USER ... WITH LOGIN.

How do I fix all orphaned users at once after a restore?

Run: EXEC sp_change_users_login 'Auto_Fix', 'username'; for each orphaned user — this creates a matching server login if one doesn't exist. For multiple users, query sys.database_principals and loop through orphaned accounts.

How do I prevent error 15023 in deployment scripts?

Use conditional creation: IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = N'username' AND type = 'S') CREATE USER [username] FOR LOGIN [loginname]; This makes the script safe to run multiple times.

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

Other authentication errors