SqlCacheDependency Constructor (String^, String^)
Initializes a new instance of the SqlCacheDependency class, using the supplied parameters to create a cache-key dependency.
Assembly: System.Web (in System.Web.dll)
Parameters
- databaseEntryName
-
Type:
System::String^
The name of a database defined in the databases element of the application's Web.config file.
- tableName
-
Type:
System::String^
The name of the database table that the SqlCacheDependency is associated with.
| Exception | Condition |
|---|---|
| HttpException | The internal check for SqlClientPermission failed. - or - The databaseEntryName was not found in the list of databases configured for table-based notifications. - or - The SqlCacheDependency object could not connect to the database during initialization. - or - The SqlCacheDependency object encountered a permission-denied error either on the database or on the database stored procedures that support the SqlCacheDependency object. |
| ArgumentException | The tableName parameter is String::Empty. |
| ConfigurationErrorsException | Polling is not enabled for the SqlCacheDependency. - or - The polling interval is not correctly configured. - or - No connection string was specified in the application's configuration file. - or - The connection string specified in the application's configuration file could not be found. - or - The connection string specified in the application's configuration file is an empty string. |
| DatabaseNotEnabledForNotificationException | The database specified in the databaseEntryName parameter is not enabled for change notifications. |
| TableNotEnabledForNotificationException | The database table specified in the tableName parameter is not enabled for change notifications. |
| ArgumentNullException | databaseEntryName is null. - or - tableName is null. |
This constructor is used to create SqlCacheDependency objects for SQL Server 7.0 and SQL Server 2000 products.
The database name passed to the database parameter must be defined in the application's Web.config file. For example, the following Web.config file defines a database named pubs for SqlCacheDependency change notifications.
<configuration>
<connectionStrings>
<add name="Pubs" connectionString="Data Source=(local); Initial Catalog=pubs; Integrated Security=true"; providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled = "true" pollTime = "60000" >
<databases>
<add name="pubs"
connectionStringName="pubs"
pollTime="9000000"
/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
</configuration>
Two exceptions are commonly thrown when this constructor is used: DatabaseNotEnabledForNotificationException and TableNotEnabledForNotificationException. If a DatabaseNotEnabledForNotificationException is thrown, you can call the SqlCacheDependencyAdmin::EnableNotifications method in exception-handling code, or use the command-line tool to set up the database for notifications. If a TableNotEnabledForNotificationException is thrown, you can call the SqlCacheDependencyAdmin::EnableTableForNotifications method or use to set up the table for notifications.
The following code example uses this constructor to create an instance of the SqlCacheDependency class that is associated with a database table named Categories in a SQL Server database named Northwind.
Available since 2.0