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 Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
52 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 102.6K Reputation points
    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?