I have an ASP.NET MVC web page which basically displays rows of a tabl开发者_开发问答e in MS SQL database through a date filter. I would like to update the web page view with new row list at the time when a new row is inserted to the database table.
What is the most efficient way to accomplish this goal? Basically, what I want is to create a callback to database server from my javascript to update the UI with new results.
Assume that number of rows in the database table is large.(~1 Million)
Thanks, cas
If the DB Updates are very frequent, then you can go ahead with a polling at specific interval method. Otherwise- you can look at using Caching with Cache SQL Dependency which will give your power with the ability to invalidate the cache when something changes in the backend.
Since you mentioned there are around a million records, I assume you would have thought through you query optimization/Indexes etc for the performance.
Easiest way is via polling.
Poll at a specific interval.
Assuming you are using int primary keys, pass the primary of the last row via javascript to an action method.
Have the action method select where id > lastrow (aka new rows).
Pass new rows back from controller as json, and render them using client side javascript. Update the "last row primary key" value for future polling.
You can use Websockets which supports bi-directional communication. You can use the SuperWebSocket, a .NET websocket server.
精彩评论