I want to create application which update their control properties at the time of table values updated from database by another user. i find a solution by refreshing a control every second by help of timer, but it is not good i want to change after updating a values not to request every second SQL Server?
2 Answers
Basically you need to have SQL post when the table is updated. This called a push model (the opposite is a pull model which you are now doing).
You can use SqlDependency for this. See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency%28v=vs.100%29.aspx
However, there is some overhead associated with a push approach. Many apps just do a query every n seconds (3 - 10) and then only update the control when the properties changed.
It really is a optimisation trade off. Is making a network request (pull model) more "expensive" than having SQL server doing the trigger and then send the update message (push model)?
2 Comments
You can use SqlDependency for this, without polling.
Implementing SQL Server 2005 Query Notifications in C# Windows Application