Wrapping CREATE EVENT NOTIFICATION
inside EXECUTE AS LOGIN = N'sa'; ... REVERT;
allows creation of a server event notification as if you logged in using the sa
account, even if that account is disabled.
A very minimal example follows. First we'll check to see if the [sa]
login is disabled:
/* Is the [sa] login disabled? */
SELECT
[sp].[name]
, [sp].[sid]
, [sp].[is_disabled]
FROM [sys].[server_principals] [sp]
WHERE [sp].[sid] = 0x01;
name |
sid |
is_disabled |
sa |
0x01 |
1 |
Create the event notification:
EXECUTE AS LOGIN = N'sa';
CREATE EVENT NOTIFICATION [notification_name]
ON SERVER
FOR <event list>
TO SERVICE N'service_name', N'current database';
REVERT;
Then check ownership of the server event notification via this query:
SELECT
[owner] = sp.[name]
, sen.*
FROM [sys].[server_event_notifications] sen
INNER JOIN [sys].[server_principals] sp ON sen.[principal_id] = [sp].[principal_id];
owner |
name |
object_id |
parent_class |
parent_class_desc |
parent_id |
create_date |
modify_date |
service_name |
broker_instance |
creator_sid |
principal_id |
sa |
notification_name |
647673355 |
100 |
SERVER |
0 |
2022-12-07 10:58:31.700 |
2022-12-07 10:58:31.700 |
service_name |
073682F8-D45B-4C41-9FD9-523C90F662A2 |
NULL |
1 |
As you can see in the results above, the owner is now sa
.