// SQL Server error reference

SQL Server error 15151: Object doesn't exist or no permission

A security statement such as ALTER LOGIN, DROP USER or GRANT named a principal or object that doesn't exist, or that you aren't allowed to see.

Error number
15151
Severity
16
Category
Permissions
Error message
Cannot %S_MSG the %S_MSG '%.*ls', because it does not exist or you do not have permission.

What it means

SQL Server raises 15151 from statements that manage security (ALTER LOGIN, DROP USER, ALTER ROLE, GRANT ... TO) when the target can't be found. Like 3701, it doesn't tell you which: the name may be wrong, it may live in another database or on the server instead of the database, or you may lack permission to see it.

Common causes

  • A typo in the login, user or role name.
  • Mixing up a server login and a database user: ALTER LOGIN works on server logins, ALTER USER on users in the current database.
  • Running in the wrong database, so the user or role isn't there.
  • Missing permission such as ALTER ANY LOGIN or ALTER ANY USER, which makes the principal invisible to you.

How to fix it

  1. Check that the server login exists.

    SELECT name, type_desc FROM sys.server_principals WHERE name = N'app_user';
  2. Check the database user or role in the database you're in.

    SELECT DB_NAME() AS current_db, name, type_desc FROM sys.database_principals WHERE name = N'app_user';
  3. Run the statement in the right database (USE SalesDb;), or as a principal with the needed permission.

Related errors

More permissions errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.