Solved

SQL Dependency Call back issue

Posted on 2007-03-23
7
221 Views
Last Modified: 2013-11-07
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");
                    }
                }
            }
        }
0
Comment
Question by:jasondole
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:xDJR1875
ID: 18785506
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.
0
 
LVL 1

Author Comment

by:jasondole
ID: 18793223
this exists in a class that is called by the page, how do you pass the httpcontext to it?
0
 
LVL 17

Expert Comment

by:xDJR1875
ID: 18793392
declare a method in the class or property in the class of type httpcontext.
pass in the httpcontext to that property or method.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:jasondole
ID: 18793405
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
0
 
LVL 17

Expert Comment

by:xDJR1875
ID: 18793669
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.

0
 
LVL 1

Author Comment

by:jasondole
ID: 18793728
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.
0
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 500 total points
ID: 18793784
You have to get the context when you are in the web page. (initialize it there) IF you try to get it in the class, the class has no context. The web page has the context.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now