In ASP.net 2.0, new features and controls have been added. Among them, in the data caching function, than ASP.net 1.1 has a great change. As we all know, the caching function of data is very important, we can put some data that does not change for a period of time in the cache, so that we do not have to read the database every time, when the next time we need this data, can be directly from the cache, greatly enhance the efficiency.
In ASP.net 1.1, the caching function of data has been better implemented, but there is a small problem, that is, if the data in the database has changed, the cache cannot be updated within the specified time, but must wait for the cache to fail. For example, if you use page caching for some of the details of a product, such as prices, in a Web page, if you modify the information in the background, the user will not see the information immediately, and delay some time to see it. In some applications, if you want to do any updates to the database, you can immediately in the cache changes in effect, in ASP.net 1.1 is more difficult to implement, and in ASP.net 2.0, you can easily implement this feature. This article will introduce the implementation of this feature in the. NET Framework 2.0 beta,visual Web Developer Express Beta.
First, in ASP.net 2.0, new caching features are provided for SQL Server 7/2000, and for the upcoming SQL Server (Yukon). This highlights the caching capabilities for SQL Server 7/2000. This new data caching feature, called SqlCacheDependency, requires the following steps to implement this function:
1, under the. NET Framework 2.0 installation directory
(default is winnt\microsoft.net\framework\v2.0.40607), start a command line tool called Aspnet_regsql.exe, such as:
Aspnet_regsql-s localhost–u sa–p 123456-d pubs–ed
The above means that the local database server localhost is specified, the login username and password are specified, and the parameter-d specifies which database to use (here is the pubs specified) database,- The ed parameter indicates that the database is allowed to use the SqlCacheDependency feature.
Next, we need to specify which table to use the data SqlCacheDependency function, such as:
Aspnet_regsql-s localhost–u sa-p 123456-ed-d pubs-et-t Authors
The above statement means that the SqlCacheDependency feature is specified for the authors table in the pubs database, with the-t argument followed by the name of the table,-et to allow the table to use the SqlCacheDependency feature. Other relevant parameters are briefly described below:
| Parameters |
Parameter meaning |
| -? |
Displays the Help features for this tool. |
| -S |
The following parameter is the name or IP address of the database server |
| -U |
The next parameter is the login username for the database. |
| -P |
The following parameter is the login password for the database |
| -E |
Use this feature when you are using Windows Integrated authentication |
| -T |
The back-connect parameter is to which table the SqlCacheDependency function is used. |
| -D |
The back-connect parameter is to which database uses the SqlCacheDependency function |
| -ed |
Allow the use of SqlCacheDependency functionality for databases |
| -dd |
Prohibit the use of SqlCacheDependency functionality to the database |
| -et |
Allows the SqlCacheDependency function to be used on the datasheet |
| -dt |
Prohibit the use of SqlCacheDependency functions on datasheets |
| -lt |
Lists which tables in the current database are already using the SqlCacheDependency feature |
SqlCacheDependency the principle of simple, is the use of aspnet_regsql this special tool, pre-set to monitor the database and tables, and add a special table in the database, open the database, you will find more than one datasheet aspnet_ Sqlcachetablesforchangenotification, as shown below: