impersonation - Problem with SQL Server "EXECUTE AS" -
I got the following setup:
There is a SQL Server DB with several tables on them The set trigger (which collects history data) is the stored procedure 'history wizard' for these triggers CLR processed with . HistoryUser User is a simple user in the database without logging in. There are enough permissions to read and write in the History table from all tables.
When I back up the DB and then restore it to another machine (in this case the virtual machine, but it does not matter), the trigger does not work anymore. In fact, the user No impersonation works for now. The user = 'HistoryUser'
generates an error even as a simple statement such as
exec ('select 3') : The database can not be executed as a principal because the principal "HistoryUser" does not exist, this type of principal can not be impersonated, or you do not have permission.
If the DB owner is a domain user, then it may be, but it is not. And even if I change it to something else (their recommended solution) this problem remains.
If I make another user without a login, then I can use it for impersonation. This is, it works just fine:
Create a User TestUser without user login, exec (select 3 ') as the user =' TestUser '
I do not want to repeat those triggers again, so is there any way that I can work current HistoryUser ?
Bump: Sorry, but this is a little necessary ...
Find the orphaned user, then solve it by linking to a login.
Detect:
USE & lt; Database_name & gt;
GO;
sp_change_users_login@action = 'report';
Go;
Resolve:
In the command given below, & lt; Login_name & gt; & Lt; Database_user & gt; With the database user specified by: USE & lt; Database_name & gt;
Live
sp_change_users_login @ action = 'update_one',
@ UserNamePattern = '& lt; Database_user & gt; ',
@ Login Name =' & lt; Login_name & gt; ';
Go
Comments
Post a Comment