views:

19

answers:

0

Hi,

I am just trying to work with Sql Cache dependency. Iam able to cache the data but I am not able to invalidate. I have enabled the service broker and also enabled the notification using :>aspnet_regsql -S -ed -d -E -et -t

the code is as follows

name = (string)HttpRuntime.Cache.Get("Details");
        SqlConnection conn = new SqlConnection(connstr);
        SqlDependency.Start(connstr);
        if(name == null)
        {
            SqlCommand cmd = new SqlCommand("Select name from dbo.employee where city = 'Delhi'", conn);


            //System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(conn);
            conn.Open();


             name = (string)cmd.ExecuteScalar()+DateTime.Now.ToString();

            SqlCacheDependency dep = new SqlCacheDependency(cmd);
            conn.Close();
            details = new entity();


            details.name = name;
            details.dateTime = DateTime.Now;

            HttpRuntime.Cache.Insert("Details", name, dep);
        }