SqlCacheDependencyAdmin.EnableNotifications(String) 方法

定义

对指定的数据库启用 SqlCacheDependency 更改通知。

public:
 static void EnableNotifications(System::String ^ connectionString);
public static void EnableNotifications(string connectionString);
static member EnableNotifications : string -> unit
Public Shared Sub EnableNotifications (connectionString As String)

参数

connectionString
String

用于连接到SQL Server数据库的连接字符串。

例外

无法建立与数据库的连接。

-或-

ASP.NET 应用程序的安全上下文无权连接到数据库。

-或-

ASP.NET 应用程序的安全上下文无权禁用数据库的通知。

示例

下面的代码示例使用 EnableNotifications 方法为 连接字符串 MyConnectionString指定的数据库启用更改通知。

有关运行示例所需的完整代码,请参阅类概述主题的 SqlCacheDependencyAdmin “示例”部分。

protected void enableNotification_Click(object sender, EventArgs e)
{
  SqlCacheDependencyAdmin.EnableNotifications(
    ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
}
Protected Sub enableNotification_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  SqlCacheDependencyAdmin.EnableNotifications( _
      ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
End Sub

注解

该方法 EnableNotifications 添加了对参数中指定的 connectionString 数据库的更改通知的支持。 运行 EnableNotifications 该方法后,如果要禁用数据库的更改通知,则必须运行 DisableNotifications 该方法。

适用于