C# / SQL Listener to tell me if a row has been inserted into a table

前端 未结 7 1115
傲寒
傲寒 2020-12-15 10:44

Can someone post sample code or tell me how to set up a listener to notify me (trigger an event) if a new row is inserted into a SQL Server database?

I don\'t want

相关标签:
7条回答
  • 2020-12-15 11:37

    You can use sql notifications to do this but you said you don't want to use the broker. Otherwise you can poll, but as mentioned this can cause performance issues.

    Another way to do this is using triggers on the database table to touch a file on the filesystem.

    exec master..xp_cmdshell 'echo changed > c:\temp\filewatcher.txt'
    

    Then use a FileSystemWatcher as you mentioned you are already doing in your application to receive a notification when the file changes.

    There are security permissions that you will need to grant to your Sql Server user to make this possible but if that is acceptable then this will work without using the broker.

    0 讨论(0)
提交回复
热议问题