Watch for a table new records in sql database

前端 未结 6 1318
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 11:36

I am using EF in a windows application and I want my application to do some tasks when a new record inserted in a certain table \"these new records will be inserted by a we

6条回答
  •  自闭症患者
    2020-12-01 11:47

    You can create an SQLCLR trigger FOR INSERT to table. This trigger can call a simple WCF Service that you can host in your application. THe assembly with the trigger needs to be registered in SQL Server. See here how to do it.

    Another approach (the simplest one): use ordinary SQL trigger that monitors INSERTs to the table and executes xp_cmdshell with a command something like "copy nul /Y some_file_with_path.txt" Your application can use FileSystemWatcher class to watch for modifications to the same file. Configure the filter to watch for last access to this particular file only. See here how to do it. Proxy account for xp_cmdshell needs to be defined on SQL Server.

    I faced the same problem a while ago. I also wasn't able to make SQl Notifications work.

提交回复
热议问题