Errors with SqlQueryNotificationStoredProcedure filled up Sql Server log

I stopped the error log from filling up by dropping the underlying service:

select * from sys.services

-- do this for every service:
drop service [SqlQueryNotificationService-7d871b6d-3868-452c-b75b-d5c5b13d0301]

Then I could go back and delete all of the queues.

Now the question is how to prevent this occurring in the future.


Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission.

You must fix this problem first:

ALTER AUTHORIZATION ON DATABASE::<dbname> TO [sa];

Now if you want to know what happens, I recommend some articles on my blog: The Mysterious Notification and When it rains, it pours. In your case, the problem is twofold:

  • an administrative mistake that resulted in a database with an orphaned dbo. This is usually the result of an attach/restore of database created by a Windows SID from an unrelated authority (i.e. a local account on a different computer).
  • a coding mistake in the use of SqlDependency in that the code omits to call the Stop() when it is done, thus failing to tear down the SqlDependency temporary infrastructure.

Normally, the activated procedure of the SqlDependency temporary infrastructure would delete the temporary queue/service/procedures, but in your case, the fact that activation cannot run because of the orphaned dbo ruins everything.

Once you fix the orphaned dbo (by running the ALTER at the start of my post), the activated procedures will be able to run and they will clean all the temporary queues, services and procedures.