No, there isn't any way to properly shutdown SqlDependency
. The design choices of using a just-in-time deployed queue and service for each application instance subscribing to query notifications makes it easy to use, but has some negative consequences, and you see them when these error messages pop in your errorlog. Most times these error messages can be safely ignored, but they may have some negative consequences.
For the brave ones one can take control of its destiny and use the more basic SqlNotification
, see Using SqlNotificationRequest to Subscribe to Query Notifications. This class does not attempt to deploy a service and queue on your behalf, it expects you to do the 'dirty work'. The upside is that you have control and can avoid the problems that plague SqlDependency
Start()
/Stop()
(permissions for start, inappropriate shutdown order etc).