Sql cache dependency, DOT NET Programming

How do we enable SQL Cache Dependency?

Below are some of the steps to enable the SQL Cache Dependency:-

  • Enable the notifications for database.
  • Enable the notifications for individual tables.
  • Enable the ASP.NET polling by using the "web.config" file
  • Finally use the Cache dependency object in your ASP.NET code

To enable notifications for the database.

Before you can use SQL Server cache invalidation, you need to enable notifications for the database. This task is done with the aspnet_regsql.exe command-line utility, which is located in the c:\[WinDir]\Microsoft.NET\Framework\[Version] directory.

aspnet_regsql -ed -E -d Northwind

-ed :- command-line switch

-E: - Use trusted connection

-S: - Specify server name it other than the current computer you are working on

-d: - Database Name

So now let's try to understand what happens in the database because of "aspnet_regsql.exe". After we execute the "aspnet_regsql -ed -E -d Northwind" command you will see one new table and four new stored procedures created.

1497_sql cache.png

Figure : - SQL Cache table created for notification

1413_sql cache1.png

Figure : - New stored procedures created

Just to make short run of what the stored procedures do.

"AspNet_SqlCacheRegisterTableStoredProcedure" :- This stored procedure fixed a table to support notifications. This method works by adding a notification trigger to the table, which will fire whenever any row is deleted,inserted , or updated,   .

"AspNet_SqlCacheUnRegisterTableStoredProcedure":- This stored procedure takes a registered table and discard the notification trigger so that notifications won't be created.

"AspNet_SqlCacheUpdateChangeIdStoredProcedure":- The notification trigger calls this stored procedure to update the AspNet_SqlCacheTablesForChangeNotification table, therefore  indicating that the table has modified.

AspNet_SqlCacheQueryRegisteredTablesStoredProcedure :- This extracts just the table names from the AspNet_SqlCacheTablesForChangeNotification table. It is used to get a quick view at all the registered tables.

AspNet_SqlCachePollingStoredProcedure :- This will get  the  complete list of changes from the AspNet_SqlCacheTablesForChangeNotification table. It is used to perform the polling.

Enabling notification for individual tables

When the necessary stored procedure and tables are generated then we have to notify by saying which table needs to be enabled for notifications.

There are 2 ways to achieve this:-

  • aspnet_regsql -et -E -d Northwind -t Products
  • Exec spNet_SqlCacheRegisterTableStoredProcedure 'TableName'

Registering the tables for the notification internally generate trigger for the tables. For instance for a "products" table the following trigger is generated  So any modifications  to the "Products" table will update the "AspNet_SqlCacheNotification' table.

CREATE TRIGGER

dbo.[Products_AspNet_SqlCacheNotification_Trigger] ON

[Products]

FOR INSERT, UPDATE, DELETE

AS BEGIN SET NOCOUNT ON EXEC dbo.AspNet_SqlCacheUpdateChangeIdStoredProcedure

N'Products'

END

The "AspNet_SqlCacheTablesForChangeNotification" contains a single record for each  table you're monitoring. When you make a change in the table (like  inserting, updating, or deleting a record), the change Id column is incremented by one .ASP.NET queries this table continuously keeps track of the most recent changed values for each  table. When this value changes in a subsequent read, ASP.NET knows that the table has changed.

357_sql cache2.png

Figure : - Entries in the Cache notification table

Posted Date: 9/21/2012 9:17:14 AM | Location : United States







Related Discussions:- Sql cache dependency, Assignment Help, Ask Question on Sql cache dependency, Get Answer, Expert's Help, Sql cache dependency Discussions

Write discussion on Sql cache dependency
Your posts are moderated
Related Questions
Perform Arithmetic operations on Floating Values - C# Program Hello, I've been trying so many codes for this but those codes didn't work well. Please write the code for Perfor

The program is broke now but explains in text and printscreens the specific things i have to do to implement new bookies new sports and change settings for looking for arbs on two

What is the difference between int and int32. There is no difference among int and int32. System.Int32 is a .NET Class and int is an alias name for System.Int32.

I want Text/Image printing Counter Project Description: Need your help in our C# programming project. We need to pass this project in two weeks starting from now to pass our

What is a fish bone diagram? Dr. Kaoru Ishikawa discovered the fishbone diagram. Therefore, it can be also known as Ishikawa diagram. The Fishbone diagram is an analysis dia

NameSpace Namespace consists of 2  main basic functionality :- NameSpace Logically types group , ex. System.Web.UI logically groups our UI related features. In Object O


What is CAR (Causal Analysis and Resolution)? The basic purpose of the CAR is to analyze all the problems, defects, and good practices/positive triggers in projects, perform a

I Need paypal and urolator pro api integrated in to aspx site Project Description: Need paypal and urolator pro api integrated in to aspx site. The is presently completed and

I want high skilled C++ programmers Project Description: I want to hire the developer, who are proficient in C/C++ and have experience with STL and work with the data structu