Results 1 to 8 of 8

Thread: need help with SqlCacheDependency

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    need help with SqlCacheDependency

    I have this code:

    Code:
            protected void Button3_Click(object sender, EventArgs e)
            {
                DataView dv2 = (System.Data.DataView)Cache["SqlSource"];
                if (dv2 == null)
                {
                 
                    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SampleDBConnectionString"].ConnectionString);
                    SqlCommand cmd = new SqlCommand("Select id, product, warehouse, quantity from inventory", con);
                    SqlCacheDependency sqlDep = new SqlCacheDependency(cmd);
    
                    SqlDataSource1.SelectCommand = "Select id, product, warehouse, quantity from inventory";
                    dv2 = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    
                    Cache.Insert("SqlSource", dv2, sqlDep, System.Web.Caching.Cache.NoAbsoluteExpiration,new TimeSpan(0, 0, 0, 5));
                }
                int x = dv2.Table.Rows.Count;
                Label2.Text = x.ToString();
            }
    For some reason, the Cache is not expiring. What is wrong with this code? I am aware that I could do this using the SqlDataSource1.SqlCacheDependency property, but I'd like to know how to do it using the SqlCacheDependency object. Could someone tell me why this code is not working?
    Last edited by benmartin101; Sep 12th, 2011 at 03:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width