Using Polling SQL Cache Dependencies with DataSource Caching
In this demo, I poll the SQL Cache dependency with DataSource caching. I achieve this by first enabling the database for cache dependency.
This can be done using the either the aspnet_regsql.exe command line
or using the SqlCacheDependencyAdmin class.
SqlCacheDependencyAdmin.EnableNotifications(connectionString);
SqlCacheDependencyAdmin.EnableTableForNotifications(ConfigurationManager.ConnectionStrings["AdminConnectionString"].ConnectionString,
strTableName);
I then add a caching element in the web.config to refresh the cache every 60 seconds
<caching>
<sqlCacheDependency
enabled="true"
pollTime="60000">
<databases>
<add
name="WEBSWAPP" connectionStringName ="WEBSWAPPConnectionString" />
</databases>
</sqlCacheDependency>
</caching>
Then I set the EnableCaching="true" SqlCacheDependency="WEBSWAPP:Address" on the SqlDataSource object. If you insert a new record in the
ListView demo, you have to wait for a minute in order for it to show up on this gridview.
The data structure is explained under the ListView demo. You can view this demo implemented in ASP.NET 2.0 .
SqlCacheDependency: Select query was executed against the database
| | Suite # | Address Line 1 | Address Line 2 | City, Province, Country | Postal Code | Type |
| Edit Delete | | Exportrådet Klarabergsviadukten 70 | Box 240 |
Nora , Örebro County , Sweden
| |
Primary
|
| Edit Delete | | Klarabergsviadukten 90 | Box 44 |
Botkyrka , Stockholm County , Sweden
| 101 20 |
Primary
|
| Edit Delete | fd | afd | fds |
Abbeville, Alabama, United States
| |
Primary
|
| Edit Delete | 232132 | 321 | 21321 |
Abbeville, Alabama, United States
| |
Primary
|
| Edit Delete | fdg | asdf | sdf |
Edmundston , New Brunswick, Canada
| 21312 |
Home
|