views:

20

answers:

0

Hi Iam adding SqlCacheDependency programmatically but Iam not able to invalidate the cache.

Iam using the following Output cache directive in the .aspx page

<%@ OutputCache   Duration="300" VaryByParam="none" %>

The code in the .aspx.cs file is:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        SqlDependency.Start(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        SqlCommand cmd = new SqlCommand("Select Title from dbo.TblMetaData where RecordId ='CMS333'", conn);
        conn.Open();
        string title = (string)cmd.ExecuteScalar();

        SqlCacheDependency dep = new SqlCacheDependency(cmd);
        Response.AddCacheDependency(dep);
        conn.Close();
        Label1.Text = title + " "+DateTime.Now.ToString();

Why is the cache not being invalidated when Iam modifying the record with id CMS333????