web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Caching Dynamics CRM Connection with Xrm with ASP.NET

(0) ShareShare
ReportReport
Posted on by 313

Hi,

I'm developing an application with Dynamics CRM SDK with Xrm in C# and ASP.NET to extract some information, and I have some problems with caching.

For example, If I obtain the price of a product that is 300, then I change it to 400, and then I reload it, I obtain 300. I don't know why is caching. If I go to IIS and stop my application,the Xrm connection it's reconnected and I obtain the right price of 400.

To fix it, I try to add this sentences in the HTML but it doesn't work.

<meta http-equiv="cache-control" content="no-cache" />

<meta http-equiv="pragma" content="no-cache" />

<meta http-equiv="expires" content="-1" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

If I restart IIS, it Works, so I think that Xrm is caching something, but I don't know how to fix it

Thanks

*This post is locked for comments

I have the same question (0)
  • BackToTheCrm Profile Picture
    on at

    Hello Santiago,

    Can you provide the part of the code where you call the CRM web service ?

  • Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    When you debug the application, are you making the calls to CRM again and it's returning the old value, or is it not making the call and the page is just refreshing?

    Thanks,

     Aiden

  • ThomasN Profile Picture
    3,190 on at

    Hi Santiago, Thank you for reaching out.

    Clement and Aiden on to it here. Depending on how you are calling the web service the connection will use cache data, like when using Service Context.

    -Tom

  • Verified answer
    ESSOUFY Profile Picture
    40 on at

    Hi Santiago,

    you can use the function below to remove a CRM cache by entity.

    public static void ClearCache(string entityName)

          {

              const string format = "adxdependency:crm:entity:{0}";

              var dependency = string.Format(format, entityName).ToLower();

              var cache = Microsoft.Xrm.Client.Caching.CacheManager.GetBaseCache();

              cache.Remove(dependency);

          }

    msdn.microsoft.com/.../microsoft.xrm.client.caching.objectcachemanager.aspx

    Thinks,

    Youssef.

  • Santiago Carbonell Profile Picture
    313 on at

    Hi,

    I'm calling XrmServiceContext every time with the onload event. For example:

    protected void Page_Load(object sender, EventArgs e)

    {

               var xrm = new XrmServiceContext("Xrm");

               // Obtenemos las empresas del parque de Maquinaria y los Contactos

               var PM = xrm.new_parquemaquinariaSet.OrderBy(i => i.new_Cliente).ToList();

               var Contactos = xrm.ContactSet.OrderBy(i => i.ParentContactId).ToList();

               foreach (var ParqueMaquinaria in PM)

               {  }

    }

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    I faced the same problem using simple connection. I added this to my web.config:

       <services default="Xrm">

         <add

          name="Xrm"

          type="Microsoft.Xrm.Client.Services.CachedOrganizationService, Microsoft.Xrm.Client"

          serviceCacheName="Xrm"

          instanceMode="PerInstance"/>

       </services>

       <serviceCache default="Xrm">

         <add

          name="Xrm"

          type="Microsoft.Xrm.Client.Services.OrganizationServiceCache, Microsoft.Xrm.Client"

          objectCacheName="Xrm"

          cacheMode="Disabled"

          returnMode="Cloned"

          queryHashingEnabled="false"  />

       </serviceCache>

       <objectCache default="Xrm">

         <add

          name="Xrm"

          type="System.Runtime.Caching.MemoryCache, System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

          instanceMode="PerInstance"

          absoluteExpiration=""

          priority="Default"

          outputCacheProfileName="Xrm"/>

       </objectCache>

    Hope it helps (did for me)!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans