Solved

SQL Dependency Call back issue

Posted on 2007-03-23
7
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
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:Daniel Reynolds
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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:Daniel Reynolds
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:
Daniel Reynolds 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Learning About The VB.NET TableLayoutPanel Control 5 42
Data Analysis 7 59
Visual Studio Start / Browser Emulator menu different 2 40
Datagridview column resizing 8 28
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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