Showing posts with label dependency. Show all posts
Showing posts with label dependency. Show all posts

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

Thursday, March 8, 2012

Caching Application Block and SQL 2005 SQL Dependency

I am building a web app using VS2005 and SQL 2005 I would like to use the Caching Application Block to cache objects from my BLL. I was wondering if there is a way of utilizing the build in SQLDependency in SQL 2005 with the Caching Application Block? Does anybody have tried this, are there any samples on the web?

Thanks,

Newbie

You can take a look at

http://msdn2.microsoft.com/en-us/library/a52dhwx7.aspx

http://msdn2.microsoft.com/en-us/library/t9x04ed2.aspx

Wednesday, March 7, 2012

Cache Dependency Problem

Hello.

I am having problems with SQL Cache dependency. I am using SQL 2005, ASP .net 2.0.

Every time i try to load data from cache, this is null. It acts like someone is constantly changing everything in the db.

Because of this my website makes hundreds of connections to the db instead of 5. This is a major issue that i cannot figure it out. PLEASE ADVISE.

On my local machine everything seems to work just fine. On the testing server the cache is always null.

Is cache dependency related

- to the platform used?

- to the number of IIS servers connected to the DB?

- to the sql user used?

Also a strange thing happens. When i change something in web.config the cache is working for about 1 min and after that it stops.

Here is the code i wrote:

public ManufacturerList GetAllManufacturers()
{
if (HttpContext.Current.Cache[ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS")] != null)
return HttpContext.Current.Cache[ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS")] as ManufacturerList;

SqlCacheDependency dep = new SqlCacheDependency(ConstantsManager.Instance.GetDefaultAsString("DB_NAME"), ConstantsManager.Instance.GetDefaultAsString("TABLE_MANUFACTURERS"));

_manufacturerList = new ManufacturerList();

DataReader reader = SqlHelper.ExecuteDataReader(WebContext.ConnectionString, CommandType.StoredProcedure, "dvx_web_MANUFACTURER_LoadAll", null);

while (reader.Read())
{
int manufacturerID = reader.GetInt("ID");

Manufacturer findManufacturer = _manufacturerList.FindByID(manufacturerID);

if (findManufacturer == null)
{
findManufacturer = new Manufacturer();
findManufacturer.LoadFromDataReader(reader);
_manufacturerList.Add(findManufacturer);
}
}

reader.Close();

HttpContext.Current.Cache.Insert(ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS"), _manufacturerList, dep);

return _manufacturerList;
}

Thanks a lot.

Hi,

Look at this article describing some ways of using SQL Dependency Cache.

http://www.ondotnet.com/pub/a/dotnet/2005/01/17/sqlcachedependency.html