Upravit

Sdílet prostřednictvím


SqlCacheDependencyAdmin.EnableTableForNotifications Method

Definition

Connects to a SQL Server database and prepares a database table or tables for SqlCacheDependency change notifications.

Overloads

EnableTableForNotifications(String, String)

Connects to the specified SQL Server database and enables the specified database table for SqlCacheDependency change notifications.

EnableTableForNotifications(String, String[])

Connects to the specified SQL Server database and enables the specified array of database tables for SqlCacheDependency change notification.

EnableTableForNotifications(String, String)

Connects to the specified SQL Server database and enables the specified database table for SqlCacheDependency change notifications.

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

Parameters

connectionString
String

A connection string used to connect to the SQL Server database.

table
String

The database table on which to enable change notifications.

Exceptions

The database is not enabled for change notifications.

table is null.

A connection to the database could not be established.

-or-

The security context of the ASP.NET application does not have permission to connect to the database.

-or-

The security context of the ASP.NET application does not have permission to disable notifications for the database.

Examples

The following code example uses the EnableTableForNotifications method to enable change notifications on the specified table in the database specified in the connection string MyConnectionString.

For the full code required to run the example, see the Example section of the SqlCacheDependencyAdmin class overview topic.

SqlCacheDependencyAdmin.EnableTableForNotifications(
  ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString,
  tableName.Text);
SqlCacheDependencyAdmin.EnableTableForNotifications( _
  ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, _
  tableName.Text)

Remarks

The EnableTableForNotifications method adds change notifications for the table specified in the table parameter, which must be in the database specified in the connectionString parameter.

Once you have used the EnableTableForNotifications method to add change notifications to a table, you must use one of the DisableTableForNotifications overloads if you wish to disable change notifications.

Applies to

EnableTableForNotifications(String, String[])

Connects to the specified SQL Server database and enables the specified array of database tables for SqlCacheDependency change notification.

public:
 static void EnableTableForNotifications(System::String ^ connectionString, cli::array <System::String ^> ^ tables);
public static void EnableTableForNotifications (string connectionString, string[] tables);
static member EnableTableForNotifications : string * string[] -> unit
Public Shared Sub EnableTableForNotifications (connectionString As String, tables As String())

Parameters

connectionString
String

A connection string used to connect to the SQL Server database.

tables
String[]

The array of SQL Server database tables on which to enable change notifications.

Exceptions

The database is not enabled for change notifications.

One of the values in the tables parameter is null.

-or-

One of the values in the tables parameter is an empty string ("").

tables is null.

A connection to the database could not be established.

-or-

The security context of the ASP.NET application does not have permission to connect to the database.

-or-

The security context of the ASP.NET application does not have permission to disable notifications for the database.

Examples

The following code example uses the EnableTableForNotifications method to enable change notifications on the tables specified in a semicolon-delimited list in the database specified in the connection string MyConnectionString.

For the full code required to run the example, see the Example section of the SqlCacheDependencyAdmin class overview topic.

SqlCacheDependencyAdmin.EnableTableForNotifications(
  ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString,
  tableName.Text);
SqlCacheDependencyAdmin.EnableTableForNotifications( _
  ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, _
  tableName.Text)

Remarks

The EnableTableForNotifications method adds change notifications for the tables specified in the tables parameter. These tables must be in the database specified in the connectionString parameter.

Once you have used the EnableTableForNotifications method to add change notifications to a group of tables, you must use one of the DisableTableForNotifications overloads if you wish to disable change notifications.

Applies to