2

I have a simple application that is showing the users a status of 10 different database values. The values in the database is updating by a 3part software and the update rate is down to every 1 seconds for some of the values and other 1-2 hours.

I need a way of getting a event call back from the SQL when there is an INSERT of “Name X” in the table.

To day my app is doing a select query to look for change every 1seconds. But I do not think this is good practice. If many users is using this app. It will be a big load on the SQL server I think.

What will be the best solution to look for updates like this?

Svein Jarle
  • 213
  • 5
  • 13
  • You want a [SQL trigger](http://stackoverflow.com/questions/5341584/sql-server-after-insert-trigger-update-another-column-in-the-same-table) – Liam Oct 12 '15 at 09:02
  • 2
    You could use [Sql Dependency](https://msdn.microsoft.com/en-us/library/62xk7953(v=vs.110).aspx) – Ric Oct 12 '15 at 09:05
  • @Liam I'd rather go with a [`SqlDependency`](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx) – DavidG Oct 12 '15 at 09:05
  • 3
    Possible duplicate of [Watch for a table new records in sql database](http://stackoverflow.com/questions/15225147/watch-for-a-table-new-records-in-sql-database) – DavidG Oct 12 '15 at 09:06
  • Thanks, I will look in to this posts. – Svein Jarle Oct 12 '15 at 09:34
  • If I understand this right,this solution will give me a callback on every insert/update. Bu I just need a call back on the update/inserts of a specific Value. (Insert where the Name=xx”) The table has updates every seconds, but my app is just monitoring some values and they are updated only 1min to 1houer. And I only need a trigger event on this updates. – Svein Jarle Oct 12 '15 at 10:05
  • Using a trigger is a viable option. Though it locks the table. Please check this before you move forward: http://stackoverflow.com/questions/2606226/sql-server-2008-running-trigger-after-insert-update-locks-original-table – d_luffy_de Oct 12 '15 at 12:26

0 Answers0