Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Dependency Call back issue

Posted on 2007-03-23
7
Medium Priority
?
243 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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