Export (0) Print
Expand All

ObjectDataSource::SqlCacheDependency Property

Gets or sets a semicolon-delimited string that indicates which databases and tables to use for the Microsoft SQL Server cache dependency.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
virtual property String^ SqlCacheDependency {
	String^ get ();
	void set (String^ value);
}
<asp:ObjectDataSource SqlCacheDependency="String" />

Property Value

Type: System::String
A string that indicates which databases and tables to use for the SQL Server cache dependency.

The ObjectDataSource control supports an optional expiration policy that is based on the SqlCacheDependency object for the data cache (the service must be configured for the database server).

SQL Server supports two mechanisms for cache invalidation: polling and notification. Each mechanism has a different syntax for the SqlCacheDependency object.

The ObjectDataSource supports only polling. The SqlCacheDependency string is used to create a SqlDependency object that is passed to the DbCommand constructor before the Select method is executed. The SqlCacheDependency string identifies databases and tables according to the same format that is used by the @ Page directive, where the first part of the string is a connection string to a SQL Server database, followed by a colon delimiter, and finally the name of the database table (for example, "connectionstring1:table1"). If the SqlCacheDependency property depends on more than one table, the connection string and table name pairs are separated by semicolons (for example, "connectionstring1:table1";connectionstring2:table2").

To support notification, you must write the cache logic in the implementation of your SelectMethod property and handle the construction of the SqlCacheDependency object in your code.

This section contains two code examples. The first code example demonstrates how to create a SQL Server cache dependency and set the SqlCacheDependency property of a ObjectDataSource object. The second code example demonstrates how to implement a wrapper method that returns a DataSet object to enable caching and filtering with an ObjectDataSource object.

The following code example demonstrates how to create a SQL Server cache dependency and set the SqlCacheDependency property of a ObjectDataSource control. In this example, the database is polled every 120 seconds. If the data in the Northwind Traders Employees table changes during that time, any data that is cached by the ObjectDataSource control and displayed by the GridView control is expired and a new set of data is retrieved on the next request for the page.

No code example is currently available or this language may not be supported.

The following code example demonstrates how to implement a wrapper method that returns a DataSet object to enable caching and filtering with an ObjectDataSource control. In the base implementation of the EmployeeLogic class, the GetAllEmployees method returns an ArrayList object. Instead of refactoring the object completely to work with the ObjectDataSource on a Web Forms page, a wrapper method named GetAllEmployeesAsDataSet is added that returns a set of NorthwindEmployee data as a DataSet.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft