SQL Server Notifications - My OnChange does not fire

前端 未结 2 1590
别那么骄傲
别那么骄傲 2021-02-10 22:12

I would like to make use of SQL Server notifications to capture insert events at my database within a winforms app. I am attempting to use the SQLDependency object. The MSDN art

相关标签:
2条回答
  • 2021-02-10 22:41

    Your first notification is the only notification you'll get. Query Notifications are not a subscription for changes, once a notification is fired it is also invalidate. You are supposed to re-submit a new notification subscription.

    If your query is notified immedeatly it means you did not get a notification for a change, but one for an invalid query. Check the values of the SqlNotificationEventArgs argument you receive. Check the Info to be Insert/Update/Delete, check the Source to be Data, check the Type to be Change.

    Have a look at the Watcher Application example to better understand how you are supposed to re-subscribe when notified. For a better understanding of how the Query Notifications work, see The Mysterious Notification.

    0 讨论(0)
  • 2021-02-10 22:57

    While I was working in the implementation of query notification, I got the exact problem. I checked all configurations, code pieces, and even TCP settings, but nothing helped. Then, I figured out the following query to run on database and it solved my problem. Maybe you can try it.

    ALTER AUTHORIZATION ON DATABASE::[Your DB] TO sa;
    
    0 讨论(0)
提交回复
热议问题