Link to home
Start Free TrialLog in
Avatar of jasondole
jasondole

asked on

SQL Dependency Call back issue

I am working on the new SQL Dependency in ASP.NET 2.0 using c# and i am having a problem with my call back method. I get to the call back method fine when the database if change but my issue is my HttpContext.Current is null when this is invoked so it never clears the cache so it can be reloaded with a new value, why is this null and what can i do to make this not null so it will run, all help is GREATLY appreciated, thanks!

        public void OnFeatureChange(string strKey, object item, CacheItemRemovedReason reason)
        {
            lock (mobjLock)
            {
                if (strKey.Equals("FeaturedResults") && reason.Equals(
                   CacheItemRemovedReason.DependencyChanged))
                {
                    if (HttpContext.Current.Cache["FeaturedResults"] != null)
                    {
                        HttpContext.Current.Cache.Remove("FeaturedResults");
                    }
                }
            }
        }
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

Does this method exist in a class or dll that is called from the page?

If this is being called into from the page, you will probably need to pass the HttpContext to the method.
Avatar of jasondole
jasondole

ASKER

this exists in a class that is called by the page, how do you pass the httpcontext to it?
declare a method in the class or property in the class of type httpcontext.
pass in the httpcontext to that property or method.
i am not entirely sure what you mean, can you give an example based off my code sniplet of what you mean pass in the httpcontext, becuase if i change the signature of my method, it wont override the call back that i need
Try something like this from the calling program

HttpContext myHttpContext = HttpContext.Current;

Then pass it to the class you are needing to work with it in.

I have tried that call but HttpContext.Current is null when i use it like that. I did that inside the class that is getting called though. What do you mean by saying then pass it to the class i am needing it to work with, where is this being passed from?  I am using SQL Dependency so this code is called  when the database changes.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial