I have a database which we want to create database USERS that are NOT mapped to server LOGINS. Then we want to have one server login, but it will EXECUTE AS USER = 'SomeUser'
to run queries against that ONE db.
But when I try to run my sql block with the EXECUTE AS
statement at the top, I am getting the error:
Cannot execute as the database principal because the principal "SomeUser" does not exist, this type of principal cannot be impersonated, or you do not have permission.
I've granted the login IMPERSONATE
on the user via:
GRANT IMPERSONATE ON USER::SomeUser TO [our-server-login]
Just for yucks, for testing (this is a test instance), I've even given the login IMPERSONATE ANY LOGIN
permission, and that did not help.
The database actually already has SET TRUSTWORTHY ON
, because it uses a number of .NET Assemblies, and that obviously is not making a difference.
Saw this question, which was fixed with TRUSTWORTHY
but that is a different scenario (needing to impersonate logins across multiple dbs).
The db is running in 2019 compatibility mode on a Sql 2019 server.