問題描述
我需要持續監視數據庫行以檢查更改(更新).如果其他來源有一些更改或更新,則應在我的應用程序上觸發事件(我使用的是 WCF).有沒有辦法連續監聽數據庫行的變化?
I have a requirement to monitor the Database rows continuously to check for the Changes(updates). If there are some changes or updates from the other sources the Event should be fired on my application (I am using a WCF). Is there any way to listen the database row continuously for the changes?
我可能有更多的事件來監視同一個表中的不同行.性能方面有什么問題嗎?我正在使用 C# Web 服務來監控 SQL Server 后端.
I may be having more number of events to monitor different rows in the same table. is there any problem in case of performance. I am using C# web service to monitor the SQL Server back end.
推薦答案
前段時間我也有過類似的需求,我用CLR SP將數據推送到消息隊列中解決了.
I had a very similar requirement some time ago, and I solved it using a CLR SP to push the data into a message queue.
為了簡化部署,我創建了一個 CLR SP,其中包含一個名為 SendMessage
的小函數,該函數只是將消息推送到消息隊列中,并使用 AFTER INSERT 觸發器(正常觸發器,而不是 CLR 觸發器).
To ease deployment, I created an CLR SP with a tiny little function called SendMessage
that was just pushing a message into a Message Queue, and tied it to my tables using an AFTER INSERT trigger (normal trigger, not CLR trigger).
在這種情況下,性能是我最關心的問題,但我對其進行了壓力測試,結果大大超出了我的預期.與 SQL Server Service Broker 相比,它是一個非常易于部署的解決方案.CLR SP 中的代碼也很簡單.
Performance was my main concern in this case, but I have stress tested it and it greatly exceeded my expectations. And compared to SQL Server Service Broker, it's a very easy-to-deploy solution. The code in the CLR SP is really trivial as well.
這篇關于C#/SQL 數據庫偵聽器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!