missing login ##MS_PolicyEventProcessingLogin## and ##MS_PolicyTsqlExecutionLogin##

Heisenberg 266 Reputation points
2024-02-21T20:10:54.98+00:00

hi Folks, On one of our sql server we are seeing missing logins ##MS_PolicyEventProcessingLogin## ##MS_PolicyTsqlExecutionLogin##. due to which we are getting error like "The activated proc '[dbo].[sp_syspolicy_events_reader]' running on queue 'msdb.dbo.syspolicy_event_queue' output the following: 'Cannot execute as the database principal because the principal "##MS_PolicyEventProcessingLogin##" does not exist, this type of principal cannot be impersonated, or you do not have permission.'" Any idea how can i recreate these logins?

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

Answer accepted by question author
Erland Sommarskog 137.6K Reputation points MVP Volunteer Moderator
2024-02-22T21:55:22.3766667+00:00

first query referencing view "sys.server_principals" doesnt return anything.

Seems like someone has dropped that login. Probably some sort of a lockdown craze.

So you need to recreate the logins. You can do it this way:

DECLARE @sql nvarchar(MAX) = 
   'CREATE LOGIN ##MS_PolicyEventProcessingLogin## WITH PASSWORD = ''' + convert(char(36), newid()) + 
      ''', SID = 0x413...
   ALTER LOGIN ##MS_PolicyEventProcessingLogin## DISABLE'
--PRINT @sql
EXEC(@sql)

Get the value that follows SID = from the sid column for the user in msdb.sys.database_principals.

The idea with newid() is that you get a random password that you never see. And never will need.

Was this answer helpful?

3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. LiHongMSFT-4306 31,621 Reputation points
    2024-02-22T02:24:34.7133333+00:00

    Hi @Heisenberg Try EXEC sp_change_users_login 'Auto_Fix', '<User Name>'

    Refer to this similar thread: What would cause an orphaned ##MS_PolicyEventProcessingLogin##?

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Kevin Snow 0 Reputation points
    2026-09-23T14:26:45.1966667+00:00

    For me, the account gets orphaned each time the replica experiences an AvailabilityGroup failover. The account has the same SID in syslogins on all replicas. However, the SID in database_Principals is different in the master and msdb databases. It seems logical that sp_change_users_login is changing the server SID to match the database SID, so the problem reoccurs each time I switch Primary replicas. I should change the database principal SID to match the server login. Dropping and recreating the database user should do that.

    Was this answer helpful?