Force ASP.NET 2.0 page refresh when the database is updated

  • Thread starter Thread starter Hrvoje Vrbanc
  • Start date Start date
H

Hrvoje Vrbanc

Hello!

I have an ASP.NET page that displays some data from an SQL Server 2005
database, using a Select query. The database is updated by another piece of
software, independently of the ASP.NET page. The ASP.NET page only displays
data and it has nothing to do with inserting or updating data.

What is the best way to force the refresh of the ASP.NET page every time a
new record is inserted in the table?

I tried to implement SQL Server cache dependency/invalidation but although
the page returned no errors, I couldn't manage to make it refresh.

Thank you in advance,
Hrvoje
 
Thank you Patrice.

The content is very plain: first name, last name, company.
Those records are added to a database table by another software, completely
independent from web page.

Web page shows those informations (SELECT TOP 1 * FROM tblUsers ORDER BY id
DESC) by using a data reader and, as can be seen from the query, displays
only the last record entered on a three label controls.

Unfortunately, due to some other considerations, refreshing at a regular
interval (even if it's a variable one by means of setting the timeout value
in codebehind and then sending it to JacaScript) is not acceptable - I would
really need the database to trigger the reload. The point is that reload
should occur very quickly after the record insert and then the same
informations should remain on screen until the next insert. I know it will
stay so with periodical reloads as well but, to make a long story short, I
can't use periodical reloads.

Thank you,
Hrvoje
 
It is simple not possible to force a refresh like this because of the
inherent nature of the web.

The closest thing you can do is polling like the other person suggested.
 
web page do not keep a connection to the server, so there is no way for the
server to send a message to the client. the usual method is as suggested to
have the client poll.

to trigger a client event from the server requires a constant connection.
there are three approaches for this

1) use a java applet that open a socket to the server. the server can then
notify the java applet, which can fire an event on the client.

2) same as above but use a browser plugin.

3) using a hidden frame and server push send events to the client. basically
the client requests a page in a hidden frame, and the server push javascript
to client in chucks via fluching. to do this with asp.net you need to up the
page timeouts. also every couple a minutes, the client shoudl close and
restablish the connection.

all three of these approaches cause heavy resource load on the server. if
you have too many clients, your server will run out of connections or process
threads. you will need to tune this carefully.

-- bruce (sqlwork.com)
 
I solved the problem by embedding a zero-width and height iFrame on the main
page. The codebehind of the page within the iFrame is refreshed every 1
second and when it notices a new record had been added to the DB table, it
refreshes the parent page with parent.location.reload(). Works good!

Hrvoje
 
Back
Top