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
Solved

SQL Dependency Call back issue

Posted on 2007-03-23
7
226 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: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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Footer for each row on Gridview 2 32
VS2013 publish C# application Created folder -- where is it??? 10 27
MailAddress in vb 4 29
Amazon S3 .Net error 5 15
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.

808 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