Msg 15517 Execute as User.
Applies to: SQL Server 2019 Developer Edition.
Date created: August 16, 2020.
Problem Description.
If you are connected to a SQL Server instance with a specific login and you
try to execute a T-SQL statement as another login, you may find the following
error:
Msg 15517, Level 16, State 1, Line 1
Cannot execute as the database principal because the principal "alberto" does
not exist, this type of principal cannot be impersonated, or you do not have
permission.
Msg 229, Level 14, State 5, Line 3
The SELECT permission was denied on the object 'tblCheques', database 'CuentasXPagar',
schema 'EmisionCheques'.
Cause.
The "morillo" login does not have "impersonate" permission on the principal "alberto".
Solution.
To resolve this error, provide "impersonate" permission to the first
login ("morillo") on the second principal ("alberto").
After that the first login will be able to impersonate the principal and execute
the statement as the principal.