Mega Code Archive

 
Categories / ASP.Net / ADO Database
 

Use SqlCacheDependencyAdmin to GetTablesEnabledForNotifications

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default_aspx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"             DataKeyNames="au_id">             <Columns>                 <asp:BoundField ReadOnly="True" HeaderText="au_id" DataField="au_id" SortExpression="au_id">                 </asp:BoundField>                 <asp:BoundField HeaderText="au_lname" DataField="au_lname" SortExpression="au_lname">                 </asp:BoundField>                 <asp:BoundField HeaderText="au_fname" DataField="au_fname" SortExpression="au_fname">                 </asp:BoundField>                 <asp:BoundField HeaderText="phone" DataField="phone" SortExpression="phone"></asp:BoundField>                 <asp:BoundField HeaderText="address" DataField="address" SortExpression="address"></asp:BoundField>                 <asp:BoundField HeaderText="city" DataField="city" SortExpression="city"></asp:BoundField>                 <asp:BoundField HeaderText="state" DataField="state" SortExpression="state"></asp:BoundField>                 <asp:BoundField HeaderText="zip" DataField="zip" SortExpression="zip"></asp:BoundField>                 <asp:CheckBoxField HeaderText="contract" SortExpression="contract" DataField="contract">                 </asp:CheckBoxField>             </Columns>         </asp:GridView>         <asp:SqlDataSource ID="SqlDataSource1"                             runat="server"                              EnableCaching="True"                              SqlCacheDependency="Pubs:Authors"                            SelectCommand="SELECT * FROM [authors]"                            ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>">         </asp:SqlDataSource>         <asp:Button ID="Button1" runat="server" Text="Enable Notifications" Width="181px" /><br />     </div>     </form> </body> </html> File: Default.aspx.vb Partial Class Default_aspx     Inherits System.Web.UI.Page     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click         EnableNotification("Authors")     End Sub     Public Sub EnableNotification(ByVal tableName As String)         Dim connStr As String = "Server=.\SQLEXPRESS;Integrated Security=True;Database=pubs;Persist Security Info=True"         Dim mustEnable As Boolean = True         Try             Dim tablesEnabled() As String             tablesEnabled = _                SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(connStr)             If (tablesEnabled IsNot Nothing) Then                 Dim table As String                 Response.Write("<b>Tables Enabled For " & _                                "Notification</b><br/>")                 For Each table In tablesEnabled                     Response.Write(table & "<br>")                     If (table.ToString.Equals(tableName)) Then                         mustEnable = False                     End If                 Next             End If         Catch ex As Exception             mustEnable = True         End Try         If mustEnable Then             SqlCacheDependencyAdmin.EnableNotifications(connStr)             SqlCacheDependencyAdmin. _             EnableTableForNotifications(connStr, tableName)             Response.Write(tableName & "<br>")         End If     End Sub End Class