can the asp page be auto refreshed trigger by database change using sqlCacheDependency

1.9k Views Asked by At

I've spent 2 whole weeks in googling some working sample on this. I was almost kind of knocking my head against concrete wall....deeply suffering until now.

Ok, I have a simple web page to display two columns, say, Msg & MsgID, from a table named MsgLog in MS SQL Server. I have stored procedure that will insert new Msg entries into the table. (in future, possibly could update existing entries)

My desire is, whenever there is a new msg entry inserted, or an existing msg entry got updated, the web page must automatically reflect this change without user clicking any page button, or without any coded timer function, otherwise the web page just leave as it is. The page refresh can only be triggered by database table change.

I read lots of internet posts regarding using SqlCacheDependency to achieve this, but none provides complete steps and codes. I tried to tweak their sample codes in my project, but none of work successfully, as I predicted. Or is it impossible to implement this?

My development environment is: Visual Studio 2010 professional, using ASP.NET FRAMEWORK 4.0, MVC 3 application using C# with embedded sql statements with SqlCommand object, database is MS SQL Server 2008 enterprise editon, IIS express.

Can someone genius to show me complete workable detailed steps from sql server setting, to coding. Functionality is just as simple as display rows with 2 columns from one table in a web page, and reflect changes realtime if and only if the table got updated or inserted. Not using polling or timer techniques; Not using LINQ to SQL, but using SqlCommand.

thanks millions of thousannds.

1

There are 1 best solutions below

4
On

This in itself doesn't have to do directly with SqlCacheDependency.
You are wanting to do something that until only recently was really done with timers/polling unless you were one of the big players (ie google chat) Once your server notification event is raised then use SignalR to notify the clients of the change, so it requires an 'open' connection. Otherwise polling/refreshing is your only option. I haven't used SignalR, but I do know its really your only option now to do what you want. There have been some other projects in this field, but this is your best bet by far.

https://github.com/SignalR/SignalR