Question

I am using the Microsoft ODBC driver on a Linux system to connect to SQL Server 2012 on Windows to use the Query Notification feature. I run my C code and can see my subscription appear in sys.dm_qn_subscriptions as I expect, then my code sends a WAITFOR and blocks - fine so far. Then I do a transaction that will trigger the notification, and I get it - still fine. What I would like to do is then process the notification and loop around again to WAITFOR but after the first notification my subscription no longer appears in the DMV. My question is, is this the intended behaviour and I should re-subscribe every time, or is something weird happening?

Was it helpful?

Solution

The query notification is removed after the message is sent so you'll need to re-subscribe if you want to continue to receive notifications. Here's the relevant excerpt from the doc you referenced.

Notifications are sent only once. For continuous notification of data change, a new subscription must be created by re-executing the query after each notification is processed.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top