的SqlDependency订阅不是从关机dm_qn_subscriptions下降是从、SqlDependency、dm_qn_subscriptions

2023-09-03 13:28:46 作者:£暗夜★噬血彡

我的的SqlDependency 的正常工作,并代理队列和服务掉下正确,当应用程序存在(我不执行的 SqlDependency.Stop(...)的为前推荐终止进程),但我注意到,所创建的通知订阅了的的SqlDependency 的生活在表中的sys.dm_qn_subscriptions后关闭应用程序。

My SqlDependency works fine, and the Broker Queue and Service get dropped properly when the application exists (I do execute SqlDependency.Stop(...) as recommended before terminating the process), yet I notice that the notification subscription created by the SqlDependency lives on in the table "sys.dm_qn_subscriptions" after the application shuts down.

如果我以后(后应用程序停机)执行的条件下,应该让这个订阅火,它似乎火,因为SQL Server将记录在事件查看器的信息消息,大意是:

If I later (post-app shutdown) execute the condition that ought to make this subscription fire, it does seem to fire, as SQL Server logs an Info message in Event Viewer to the effect that:

在谈话处理查询通知对话框   {3F03B693-C0A5-E211-A97B-E06995EBDB20}。由于下面的封闭   错误: -8490 无法   找到远程服务   者; SqlQueryNotificationService-0ea1f686-e554-4e25-aa7d-4f6d85171cc3者;   因为它不存在。

The query notification dialog on conversation handle '{3F03B693-C0A5-E211-A97B-E06995EBDB20}.' closed due to the following error: '-8490Cannot find the remote service 'SqlQueryNotificationService-0ea1f686-e554-4e25-aa7d-4f6d85171cc3' because it does not exist.'.

和订阅,然后从sys.dm_qn_subscriptions。

and the subscription is then dropped from "sys.dm_qn_subscriptions".

注:申购也触发时正确的应用程序是活的。实在不行错就我的应用程序而言,但它让我担心的是,订阅未在数据库系统表会自动消灭,一旦他们依赖于被终止代理队列/服务。这可能会导致(至少是),以幻/亡灵预约记录累积在数据库中的丰度和减少不必要的事件查看器(每个应用程序的运行产生的sys.dm_qn_subscriptions新不死的记录)的SQL Server清理的消息。

Note: the subscription also fires properly when the application is alive. Nothing works wrong as far as my application is concerned, but it worries me that the subscriptions are not wiped automatically in the database system table once the broker queue/service they depend on are terminated. This can lead (at the very least) to an abundance of phantom/undead subscription records accumulating in the database and to needless SQL Server cleanup messages in Event Viewer (each app run generates new undead records in "sys.dm_qn_subscriptions").

时的这种行为正常吗?可事情可以做更整洁?

Is this behaviour normal? Can things be made neater?

在此先感谢,

ð。

推荐答案

这是正常行为。 QN是长寿命的时候,就会触发一个后重新启动数据库(因此也将在服务器重新启动后火)。但的SqlDependency 设置临时服务/队列接收通知和这些应该是使用的对话框定时器和的内部激活。这两个机制的互动方式是你所看到的,错误日志污染。没事的坏的情况,至少不通常的,但显然不是工整。

This is the normal behavior. QN are long lived and they will fire upon a database restart (thus also will fire after a Server restart). But SqlDependency sets up a temporary service/queue to receive the notifications and these are supposed to be tear down in case of crash by using a dialog timer and internal activation. The way these two mechanisms interact is what you see, the ERRORLOG pollution. Nothing bad happens, at least not usually, but is obviously not neat.

罐头的东西制成整洁?

Can things be made neater?

您可以使用滚动自己的解决方案直接 SqlNotificationRequest 它不再提供创建服务/队列收到您的应用程序域的通知,并将其路由到适当的 SqlDependency.OnChange的服务 事件。有可行的替代方案,这取决于确切的情况。但是,是相当低的水平的工作,你可能最终解决一个糟糕的方​​式比原来的的SqlDependency 解决方案...

You can roll your own solution using directly SqlNotificationRequest which no longer provides the 'services' of creating a service/queue to receive your appdomain notifications and route them to the appropriate SqlDependency.OnChange event. There are viable alternatives, depending on the exact scenario. But is fairly low level work and you may end up solving the problems in a worse manner than the original SqlDependency solution...

顺便说一句,没有办法'降'挂起QN订阅应用程序退出。问题是固有的用作由QN通知传递机构的单向的对话框。适当的通知(订阅)应当由用户发起,并且通知应当从靶(通知)响应消息发送回引发剂(订户)。

BTW there is no way to 'drop' the pending QN subscription on application exit. The problem is inherent in the one-way dialogs used as notification delivery mechanism by QN. Proper notifications (subscriptions) should be initiated by the subscriber and the notification should be a response message from target (notifier) back to initiator (subscriber).