Sunday, March 11, 2012

Caching Set Up Problem

Hi Expert,

Hmm Am I doing it right? Can you give me any suggestions please? Thank you!!
I followed the way for setting up the sql cache dependency fromhttp://quickstarts.asp.net/QuickStartv20/aspnet/doc/caching/SQLInvalidation.aspx.
However, I still have the following error:

When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.

IssueSummary.aspx
<%@.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="true"CodeFile="IssueSummary.aspx.vb"Inherits="IssueSummary"title="Issue Summary" %>
<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="cc2" %>
<%@.RegisterAssembly="Microsoft.Web.Atlas"Namespace="Microsoft.Web.UI"TagPrefix="cc1" %>
<%@.OutputCacheDuration="999999"VaryByParam="None"SqlDependency="CommandNotification" %>

Global.asax
Sub Application_Start(ByVal senderAsObject,ByVal eAs EventArgs)
Dim connectionStringAsString = ConfigurationManager.ConnectionStrings("ICTConnectionString").ConnectionString
Dim needToInstallAsBoolean =True
Try
Dim tables()AsString
tables = SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(connectionString)
If (Not tablesIsNothing)Then
Dim tblAsString
ForEach tblIn tables
If (tbl.ToLower().Equals("IssueDetails"))Then
needToInstall =False
EndIf
Next
EndIf
Catch exAs Exception
needToInstall =True
EndTry
If (needToInstall)Then
SqlCacheDependencyAdmin.EnableNotifications(connectionString)
SqlCacheDependencyAdmin.EnableTableForNotifications(connectionString,"IssueDetails")
EndIf
EndSub

Web.config
<connectionStrings>
<addname="ICTConnectionString"connectionString="Data Source=jamesle-3;Initial Catalog=IssueCommunicationTool;Integrated Security=True"providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependencyenabled="true"pollTime="1000" >
<databases>
<addname="ICTDB"connectionStringName="ICTConnectionString" />
</databases>
</sqlCacheDependency>
</caching>

SQL Server 2005 - Database - IssueCommunicationTool
SELECT is_broker_enabledFROMsys.databasesWHEREname='IssueCommunicationTool'

Return = 1, it means the broker service is enabled. Also, the database has created the table ASPNET_SQLCacheTableForChangeNotification,
the trigger in IssueDetails table, and some other store procedures.

To use that the notification service nees to be enable, does not look like it is in your configuration.|||

Just thought that if loading them dynamicly you may want just to add the user control in the code behind

Cache["Myusercontrol"] = usercontrolname;

grab them

if ( Cache["Myusercontrol"] != null )

{

usercontrolname = (UserControl) Cache["Myusercontrol"];

}

|||

You are messing the both ways for SQL caching - polling and notifications. Polling is for both 2000 and 2005 version, whether notifications is only for 2005, because of the Service Broker.

In your case you have been usingSqlDependency="CommandNotification" in the outputcache directive. This means that you are using notification based invalidation. In such case you should call SqlDependency.Start(connectionString) in the Application_OnStart method (Global.asax file). In such case you did not need any settings in the web.config file. You need then only if you use polling based invalidation. This is all written down on the page that you point. Just read it more carefully.Wink

No comments:

Post a Comment