停止的SqlDependency优雅 [英] Stopping SqlDependency gracefully

查看:229
本文介绍了停止的SqlDependency优雅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有利用的SqlDependency对象跟踪底层数据库中的数据的某些表变化的应用程序。

I have an application that utilizes SqlDependency objects to track changes on certain tables of data in an underlying database.

有关他们的工作以及在大多数情况下,但是,我发现,当我尝试使用静态杀依赖停止()之类的方法,我得到以下异常:

For the most part they work well, however, I noticed when I try to kill the dependency using the static Stop() method of the class, I get the following exception:

当前命令发生了严重错误。结果,如有的话应该被丢弃。用户取消操作。

A severe error occurred on the current command. The results, if any, should be discarded. Operation cancelled by user.

这是对所有运行时提供的信息。在数据库端日志充斥着重复的错误类型:

That's about all the information the runtime provides. On the databases end the log is littered with a repeating type of error:

在会话句柄
中的查询通知对话框{ 。59CC17D7-DB61-E311-BF57-00151796FDC4}'关闭,由于下面的$ b​​ $ b错误:8490无法找到远程服务
'SqlQueryNotificationService-058a0d35-359a-478E-b227-427d7dabc62c
因为它不存在

The query notification dialog on conversation handle '{59CC17D7-DB61-E311-BF57-00151796FDC4}.' closed due to the following error: 8490 Cannot find the remote service 'SqlQueryNotificationService-058a0d35-359a-478e-b227-427d7dabc62c' because it does not exist.

据推测,这是应用程序的不正确端接的依赖性的结果,并留下了与通知服务僵尸条目。它不会出现是造成任何不良影响,但对于未终止正确的日志被这些通知错误充斥每一个客户......且不说它只是不好的做法。

Presumably, this is a consequence of the application not terminating the dependency correctly, and leaves the notification service with zombie entries. It doesn't appear to be causing any adverse effects, but for every client that isn't terminating correctly the log gets flooded with these notification errors... Not to mention it's just bad practice.

这是怎么回事?我认为,通过调用停止(),所有现有的手柄来改变事件将被释放。如果不是这种情况,你会怎么优雅地释放所有打开的句柄?我做不到的明确地的释放他们,因为查询到的数据是动态的应用驱动;我不知道在任何给定的时间什么用户决定拉。只有他们询问被依赖的约束。

Why is this happening? I would think that by calling Stop(), all existing handles to change events would be released. If this is not the case, how would you gracefully release all open handles? I can't explicitly release them because the queries to the data are dynamically driven by the application; I don't know at any given time what the user decided to pull. Only what they queried is bound by a dependency.

推荐答案

没有,没有任何方式的正常的停机时的SqlDependency 。用刚刚在部署时间排队和服务为每个应用程序的实例的订阅的查询通知使得它易于使用,但有一些消极的后果,你看他们时,这些错误消息在错误日志弹出。多数情况下,这些错误消息可以放心地忽略,但他们可能一些消极后果

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.

对于胆大的人可以利用其命运的控制权,并使用更基本的 SqlNotification ,请参见使用SqlNotificationRequest来订阅查询通知。这个类并不试图以您的名义部署服务和队列,它希望你做脏活。的好处是,你有控制,可避免困扰的问题的SqlDependency 开始() / 的stop()(用于启动,不适当的关机命令等权限)。

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).

这篇关于停止的SqlDependency优雅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆