Why does impersonation (Execute as) work in a User database and not in the master database in Azure SQL DB?

Jerimy Stanley 0 Reputation points
2024-05-21T17:00:07.2233333+00:00

Execute As User = 'User1' doesn't work in the Azure SQL DB master database. User1 account created in the master database and in a user database. Execute As User works in the user database and in the master database, receives the error: Msg 15517, Level 16, State 1, Line 7 - Cannot execute as the database principal because the principal "user1" does not exist, this type of principal cannot be impersonated, or you do not have permission. Why doesn't Execute As work in the master database in Azure SQL DB?

Azure SQL Database
SQL Server | SQL Server Transact-SQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2024-05-21T21:26:35.04+00:00

    My guess is that a database principal in the master database for Azure SQL Database is more akin to a login. That is, it is there to permit users to log in and be authenticated. And as a side effect of this, EXECUTE AS is broken.

    What are you trying to do with EXECUTE AS in master?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.