SELECT NAME, IS_BROKER_ENABLED FROM SYS.DATABASES
ALTER DATABASE <database> SET ENABLE_BROKER
<%@ Application Language="C#" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { // Assuming ConnectionString property in Database class contains the connection string to connect to Sql Server System.Data.SqlClient.SqlDependency.Start(Database.ConnectionString); } void Application_End(object sender, EventArgs e) { System.Data.SqlClient.SqlDependency.Stop(Database.ConnectionString); } // remaining code </script>
<%@ Page Language="C#" %> <%@ Import Namespace = "System.Data.SqlClient" %> <%@ Import Namespace = "System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { DataTable dt = (DataTable) Cache.Get("books"); if (dt == null) { lblMsg.Text = "Creating cache"; using (SqlConnection cn = new SqlConnection(Database.ConnectionString)) { SqlCommand cmd = new SqlCommand("select title,author,price from dbo.books", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); SqlCacheDependency dependency = new SqlCacheDependency(cmd); DataSet ds = new DataSet(); da.Fill(ds, "books"); dt = ds.Tables[0]; Cache.Insert("books", dt, dependency); } } else lblMsg.Text = "Using Existing Cache"; GridView1.DataSource = dt; GridView1.DataBind(); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> <p /> <asp:Label ID="lblMsg" runat="server" Text="" EnableViewState ="false"></asp:Label> </div> </form> </body> </html>