Sql cache dependency, DOT NET Programming

Assignment Help:

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


Related Discussions:- Sql cache dependency

Xml text reader, What is XML Text Reader? The "XmlTextReader" class hel...

What is XML Text Reader? The "XmlTextReader" class helps to give fast access to streams of XML data in a forward-only and read-only manner. The XMLTextReader also checks if the

In search of urgent assistance with loading an asp.net site, In search of u...

In search of urgent assistance with loading an ASP.net website In search of assistance with loading an ASP.net website installation onto a new server, job will start nearly D

Full time contractual programming position, Project Description: This is...

Project Description: This is a full time contractual role seeking for a sports advisory service. We are data insights consultancy specializing in sports. We consult to a number

Get the results of a google search query, Project Description: My needs ...

Project Description: My needs are simple; the application will: - Get the results of a Google search query (The title, URL, the description, time posted) - Apply definite

Develop a simple .net software, I am seeking someone who can design customi...

I am seeking someone who can design customized software for me, preferably in .NET. I have a sql server backend which i would like to use so you only have to work with the front en

Urgently requires a jquery expert, Project Description: Looking for a JQ...

Project Description: Looking for a JQuery expert that will develop a customizable product selection page to work with our asp.net website. Product selection, size, quantity, pri

What is data independence, What is Data Independence? Data independenc...

What is Data Independence? Data independence means that "the application is independent of the storage structure and access method of data". In other words, the ability to cha

Jquery and mvc 4.5 training session, I am looking individuals who have indu...

I am looking individuals who have industry experience working on Microsoft Technology and Jquery ( MVC 4.5 ), who will take live online session and give training through Team Viewe

Create a calculator application using web form, Create a Calculator applica...

Create a Calculator application using Web Form with the following functions: 1.  Add 2.  Minus 3.  Multiply 4.  Divide Each of the above has to be a Web Service

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd