Recently, I tried out a Policy-Based Management tutorial. When I got to the point where it was supposed to prevent somebody from creating a stored procedure not named a certain way, I kept getting a weird error: “The EXECUTE permission was denied on the object ‘sp_syspolicy_dispatch_event'”. Checking it online, I found absolutely no help, so I gave up on the task.
Then, today, I added an extended event on my server to check non-critical errors. I kept getting the following error: 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.
Looking this latter problem up, I found out that the ##MS_PolicyEventProcessingLogin## account was bad on the msdb database. Well, fixing that is easy:
use msdb exec sp_change_users_login 'report' exec sp_change_users_login 'AutoFix', '##MS_PolicyEventProcessingLogin##'
Running sp_change_users_login ‘report’ should return the ##MS_PolicyEventProcessingLogin## account. If it does, you’re in luck and you can run the AutoFix to re-sync the database user with the instance login. Doing this cleared up both problems in one fell swoop.