Hi @Hammi Amine,
Thanks for your information.
I noticed this error information:
System.Data.SqlClient.SqlException: Only System Administrator can specify WITH LOG option for RAISERROR command.
This means you don't have permission to use the WITH LOG option. Please look at this article. You need to be member of the sysadmin fixed server role or users with ALTER TRACE permissions.
In addition, from the solution you've used:
EXECUTE AS USER = '##MS_PolicyEventProcessingLogin##' GO EXEC dbo.sp_syspolicy_events_reader GO
I think missing logins will cause the issue you meet.
Could you please post what do the two SELECT return? Thanks for your understanding.
SELECT * FROM sys.server_principals WHERE name IN ('##MS_PolicyEventProcessingLogin##', '##MS_PolicyTsqlExecutionLogin##')
SELECT * FROM msdb.sys.database_principals WHERE name IN ('##MS_PolicyEventProcessingLogin##', '##MS_PolicyTsqlExecutionLogin##')
Regards,
Lucy Chen
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.
https://docs.microsoft.com/en-us/answers/support/email-notifications