Abhijit barua

Abhijit barua

  • 1.2k
  • 508
  • 310k

How can i implement push based sql dependency.

May 4 2012 12:06 AM
I want to implement push based sql dependecy for auto update of gridview data when database have some changes. I change database(sql server 2008) broker now it is enable, i also grant priviledge. I write code to test in .cs page like below.

if (Cache["test"] == null)
        {
         
            string connectionString = ConfigurationManager.ConnectionStrings["book"].ConnectionString;
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlDataAdapter ad = new SqlDataAdapter("SELECT * from test", myConnection);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            SqlCacheDependency sqlDepend = new SqlCacheDependency(ad.SelectCommand);
       
            Cache.Insert("test", ds, sqlDepend);
        }
        GridView2.DataSource = Cache["test"] as DataSet;
        GridView2.DataBind();

And in web config i put like below
 <caching>
 
      <sqlCacheDependency enabled="true">
        <databases>
          <add connectionStringName="book" name="book"/>
        </databases>
      </sqlCacheDependency>
    </caching>





Answers (7)