Click here to Skip to main content
15,888,351 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: BroadcastMessage Pin
MaulikDusara19-Sep-11 2:14
MaulikDusara19-Sep-11 2:14 
Questionasp.net 2010 web.config Pin
Member 821751716-Sep-11 6:59
Member 821751716-Sep-11 6:59 
Questionhow to send mail without internet connection Pin
sathyan_829416-Sep-11 6:43
sathyan_829416-Sep-11 6:43 
AnswerRe: how to send mail without internet connection Pin
Richard MacCutchan17-Sep-11 1:20
mveRichard MacCutchan17-Sep-11 1:20 
GeneralRe: how to send mail without internet connection Pin
GenJerDan17-Sep-11 1:51
GenJerDan17-Sep-11 1:51 
GeneralRe: how to send mail without internet connection Pin
Richard MacCutchan17-Sep-11 2:46
mveRichard MacCutchan17-Sep-11 2:46 
QuestionMVC3 DropDownList Question Pin
eddieangel16-Sep-11 6:41
eddieangel16-Sep-11 6:41 
QuestionNeed lowdown on my custom CacheDependency implementation [modified] Pin
Jaime Premy15-Sep-11 16:46
professionalJaime Premy15-Sep-11 16:46 
Sigh | :sigh: I've been using Data CacheDependency for a while now for my XML File based data.

But then I suddenly had the need to use a data cache for my SQL Server based Products table and started looking around for some help.

Then I found this:

http://www.asp.net/data-access/tutorials/using-sql-cache-dependencies-vb

After taking a look at this tutorial, I said "Wow, there goes my sunday afternoon!".

But being lazy as I am, I started wondering if there wouldn't be an easier way for achieving what I wanted, and this is what I came up with.

1. I created a Table named TableChanged with 2 columns:

- TableName varchar(20)

- Changed bit

The idea is to track changes made to other tables; for the time being there is only 1 row in it:

TableName Changed
Products True

2. I created a trigger in the Products table:

SQL
CREATE TRIGGER Changed

ON dbo.Products

AFTER INSERT, UPDATE, DELETE

AS

Update  TableChanged Set Changed = 1 WHERE TableName='Products' 

So everytime something changes in Products, the value of Changed becomes True, in TableChanged.

I created the same trigger in table Categories, since it's related to Products.

3. In PageLoad I did:

VB
If Not IsPostBack Then            
Dim dv As DataView
            Dim changed As Boolean = Global.CheckChanged("Products")
            If changed Then
                dv = LoadDV()
            Else
                dv = Cache("cachedDV")
                If dv Is Nothing Then 'in case application restarts, changed will be false and dv null
                    LoadDV()
                    dv = Cache("cachedDV")
                End If
            End If

Protected Function LoadDV() As DataView
        Dim dt As DataTable = Product.GetDiscounted
        Dim dv As DataView = New DataView(dt)
        Global.UpdateChanged("Products")
        Cache("cachedDV") = dv
        Return dv
    End Function


Global and Product are classes in my BOL which handles the dataconnection thru my DAL. The sprocs used for CheckChanged and UpdateChanged are the following:

SQL
ALTER PROCEDURE dbo.TableChangedCheck
	@sTable varchar(20)
AS
	SET NOCOUNT ON
	Select Changed From TableChanged WHERE TableName=@sTable
	RETURN

ALTER PROCEDURE dbo.TableChangedUpdate
	@sTable varchar(20)
AS
	SET NOCOUNT ON
	UPDATE TableChanged SET Changed = 0 WHERE TableName=@sTable
	RETURN


So, on Pageload, if changed = true the dataview gets populated from the db and is added to the cache, while the row "Products" in TableChanged gets flagged as False.
On subsequent Pageloads, changed = false, so the dv gets populated from the cached dv;
And this goes on until either the Products or Category table get altered or the application restarts.
Very well then, this seems to work. My question is now why would the people at MS dream up
the SqlDependency Class if the same result can be achieved in this (apparently) much simpler manner?
What are the hidden pitfalls, drawbacks, disadvantages, if any, of my custom implementation.
I was hoping someone more experienced on the subject could reassure me to stay with it.
In this case it might help out others too, looking for the same thing.

Thank u for your attention
Jaime Premy


modified on Friday, September 16, 2011 8:43 AM

AnswerRe: Need lowdown on my custom CacheDependency implementation Pin
Parwej Ahamad15-Sep-11 19:22
professionalParwej Ahamad15-Sep-11 19:22 
QuestionNeed help with Multi Select Drop down display Pin
Parul Jee15-Sep-11 10:46
Parul Jee15-Sep-11 10:46 
AnswerRe: Need help with Multi Select Drop down display Pin
MaulikDusara19-Sep-11 2:17
MaulikDusara19-Sep-11 2:17 
Questionasp.net buttons Pin
jassiedog15-Sep-11 10:08
jassiedog15-Sep-11 10:08 
AnswerRe: asp.net buttons Pin
Parwej Ahamad15-Sep-11 19:27
professionalParwej Ahamad15-Sep-11 19:27 
QuestionAccess physical file in AS 400 from stored procedure Pin
Member 322226415-Sep-11 6:11
Member 322226415-Sep-11 6:11 
Questionweb forms 2010 Pin
classy_dog15-Sep-11 5:21
classy_dog15-Sep-11 5:21 
Questionvs 2008 asp.net Pin
classy_dog15-Sep-11 5:20
classy_dog15-Sep-11 5:20 
QuestionModalPopUpExtender Not showing on IE9 Pin
Vasanthakumar14-Sep-11 19:44
Vasanthakumar14-Sep-11 19:44 
AnswerRe: ModalPopUpExtender Not showing on IE9 Pin
Satish_S15-Sep-11 20:03
Satish_S15-Sep-11 20:03 
QuestionControl is null while using generic method [modified] Pin
kstxx14-Sep-11 7:01
kstxx14-Sep-11 7:01 
GeneralImport Google Mail Contacts in Your ASP.NET Web Application Pin
AditSheth13-Sep-11 18:49
AditSheth13-Sep-11 18:49 
QuestionEnvironment.CurrentDirectory and Multiple Page Requests Pin
Nathan Stiles13-Sep-11 17:48
Nathan Stiles13-Sep-11 17:48 
Questionjavascript alert Pin
Dushan12313-Sep-11 15:20
Dushan12313-Sep-11 15:20 
AnswerRe: javascript alert Pin
Shah Rizal13-Sep-11 22:14
Shah Rizal13-Sep-11 22:14 
QuestionMethod not firing Pin
Rick van Woudenberg13-Sep-11 12:56
Rick van Woudenberg13-Sep-11 12:56 
AnswerRe: Method not firing Pin
Pravin Patil, Mumbai13-Sep-11 19:50
Pravin Patil, Mumbai13-Sep-11 19:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.