Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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
XML
<caching>
     <sqlCacheDependency enabled="true">
       <databases>
         <add connectionStringName="book" name="book"/>
       </databases>
     </sqlCacheDependency>
   </caching>
Posted
Updated 3-May-12 19:40pm
v2
Comments
Sandeep Mewara 4-May-12 1:42am    
Not very clear. Can you please elaborate a little more?
If needed, Use the "Improve question" link to edit your question and provide more information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900