943,071 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 896
  • ASP.NET RSS
Jun 23rd, 2009
0

SQLCacheDependency not notifying

Expand Post »
Hi everybody
I have coded a LINQ SiteMapProvider for my ASP.NET site. The site pages info is stored in a MSSQL database.
When I make changes to the SitePAges table, the SiteMap does not reset. Here is my code
ASP.NET Syntax (Toggle Plain Text)
  1. Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
  2. If RootMapNode IsNot Nothing Then Return RootMapNode
  3. dcx = New GrabdayDataContext
  4. RootMapNode = Nothing
  5. Dim SitePages = From q In dcx.SitePages Where q.ParentID Is Nothing
  6. Dim cmd As New SqlCommand("select sitepageid, parentid from SitePages", New SqlConnection(ConfigurationManager.ConnectionStrings("Grabday").ConnectionString))
  7. Dim dependency = New SqlCacheDependency(cmd)
  8. RootMapNode = SitePageNode(SitePages.FirstOrDefault)
  9. AddNode(RootMapNode, Nothing)
  10. AddChildNodes(RootMapNode, SitePages.FirstOrDefault)
  11. HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))
  12. Return RootMapNode
  13. End Function
  14.  
  15. Sub OnSiteMapChanged()
  16. Clear()
  17. End Sub
If i understand correctly, the OnSiteMapChanged sub is supposed to run as soon as the tableset becomes invalidated, which somehow never occurs. I put dependenct.start and dependency.stop in my global.asax file in app_start and app_end respectively

My debugging shows that the "Insert" code to the cache does occur, though i dont understand why it is needed (the code was ported from a sqlsitemapprovider). doesnt asp.net cache the data on its own? it definetly does.

Can someone help me get my data invalidated or whatever?
my db show that Is_Broker_Enabled is on
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yisman is offline Offline
8 posts
since Feb 2009
Jun 23rd, 2009
0

Re: SQLCacheDependency not notifying

Welcome.

Your code is incomplete for any suggestion. Please read this Article.
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008
Jun 23rd, 2009
0

Re: SQLCacheDependency not notifying

hi
soory, i havent meant to skimp. I just thought to keep the code to only waht is necessary.
I am going over the article you sent me, meanwhile, here is the complete Provider Class
Please point out where im misatking
thanks
ASP.NET Syntax (Toggle Plain Text)
  1. Imports System.Collections.Specialized
  2. Imports System.Data.SqlClient
  3. Imports System.Configuration
  4. Imports System.Web.Caching
  5. Imports System.Collections.Generic
  6.  
  7. Public Class LINQSiteMapProvider
  8. Inherits StaticSiteMapProvider
  9. Dim dcx As GrabdayDataContext
  10. Dim RootMapNode As SiteMapNode
  11. Dim UserID As Integer
  12. Const _cacheDependencyName As String = "__SiteMapCacheDependency"
  13.  
  14.  
  15. Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As System.Collections.Specialized.NameValueCollection)
  16. MyBase.Initialize(name, attributes)
  17. dcx = New GrabdayDataContext
  18. End Sub
  19.  
  20. Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
  21. If RootMapNode IsNot Nothing Then Return RootMapNode
  22. dcx = New GrabdayDataContext
  23. RootMapNode = Nothing
  24. Dim SitePages = From q In dcx.SitePages Where q.ParentID Is Nothing
  25. Dim cmd As New SqlCommand("select sitepageid, parentid from SitePages", New SqlConnection(ConfigurationManager.ConnectionStrings("Grabday").ConnectionString))
  26. Dim dependency = New SqlCacheDependency(cmd)
  27. RootMapNode = SitePageNode(SitePages.FirstOrDefault)
  28. AddNode(RootMapNode, Nothing)
  29. AddChildNodes(RootMapNode, SitePages.FirstOrDefault)
  30. HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))
  31. Return RootMapNode
  32. End Function
  33.  
  34. Protected Overrides Function GetRootNodeCore() As System.Web.SiteMapNode
  35. BuildSiteMap()
  36. Return RootMapNode
  37. End Function
  38.  
  39. Sub AddChildNodes(ByVal ParentNode As SiteMapNode, ByVal ParentPage As SitePage)
  40. Dim childs = From q In dcx.SitePages Where q.ParentID = ParentPage.SitePageID
  41. Dim NewNode As SiteMapNode
  42. For Each sp In childs
  43. NewNode = SitePageNode(sp)
  44. AddNode(NewNode, ParentNode)
  45. AddChildNodes(NewNode, sp)
  46. Next
  47. If ParentPage.PageName = "OrdersByStatus" Then
  48. Dim statusses = From q In dcx.OrderEvents Select q.Brief Distinct
  49. Dim roles As String() = {}
  50. Dim nvc As New NameValueCollection
  51. nvc.Item("PageName") = "Orders"
  52. For Each os As String In statusses
  53. NewNode = New SiteMapNode(Me, os & "Orders", "~\Admin\Orders.aspx?Status=" & os, os & " Orders", os & " Orders", roles, nvc, New NameValueCollection, "")
  54. AddNode(NewNode, ParentNode)
  55. Next
  56. End If
  57. End Sub
  58.  
  59. Function SitePageNode(ByVal SitePage As SitePage) As SiteMapNode
  60. Dim nvc As New NameValueCollection
  61. nvc.Item("PageName") = SitePage.PageName
  62. Dim roles As String() = {}
  63. Return New SiteMapNode(Me, SitePage.SitePageID, If(SitePage.URL, "~\Admin\Menu.aspx" & "?ID=" & SitePage.SitePageID), SitePage.Title, SitePage.Description, roles, nvc, New NameValueCollection, "")
  64. End Function
  65.  
  66. Sub OnSiteMapChanged()
  67. Clear()
  68. End Sub
  69.  
  70. End Class
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yisman is offline Offline
8 posts
since Feb 2009
Jun 23rd, 2009
0

Re: SQLCacheDependency not notifying

Let's see web.config provider entry.
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Flv Player in ASP.NET
Next Thread in ASP.NET Forum Timeline: Notify alert message while navigating to other page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC