MS CRM 2011: XrmServiceContext is not fetching updated data from CRM

Proposed Answer MS CRM 2011: XrmServiceContext is not fetching updated data from CRM

  • Saturday, 21 April 2012 11:58 PM
     
     
    Hi there,
     
    I've a windows service which is designed to run continuously with some interval between each iteration. So, till the time the windows service completes its iteration, I am updating a field on one of the CRM record and I want the windows service to fetch this updated record during consecutive runs. I am using XrmServiceContext object and Linq to get this record. So during next run of the windows service, the XrmServiceContext object is not returning the updated record.
     
    Earlier I had initialized my XrmServiceContext globally in my code. It was not giving me the updated record. Then I reinitialized the XrmServiceContext in the code during operation. However, still I am not getting the updated record during the consecutive run unless I reset the windows service (which I don't want). I want the windows service to fetch the updated records during each run.
     
    So, can anyone help me resolve this issue?
     
    Thanks,
    Abhi
    • Edited by abhidrocks Sunday, 22 April 2012 12:01 AM Updated with proper comments.
    •  

All Replies

  • Sunday, 22 April 2012 12:04 AM
     
     Proposed Answer

    Hi Abhi,

    It looks you have a cache problem, check this link for cache settings you might need to apply on you app.config

    http://msdn.microsoft.com/en-us/library/gg695805.aspx

     


    Regards,
    Damian Sinay

    • Proposed As Answer by dsinayMVP Sunday, 22 April 2012 2:29 AM
    •  
  • Sunday, 22 April 2012 12:15 AM
     
      Has Code

    Yes dsinay, you are right!

    This is how my app.config file looks like:

    <?xml version="1.0"?>
    <configuration>
      <!--<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>-->
      <connectionStrings>
        <add name="Crm" connectionString="Url=https://crm.testorg.co.uk; User ID=user1; Password=password1;"/>
      </connectionStrings>
      <appSettings>
        <add key="Test" value="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Test;Data Source=Test"/>
      </appSettings>
      <system.net>
        <defaultProxy useDefaultCredentials="true">
          <proxy usesystemdefault="True" />
        </defaultProxy>
      </system.net>
    </configuration>
    

    In .cs file, I am just initializing it like shown below:

    Microsoft.Xrm.Client.CrmConnection Crm = new Microsoft.Xrm.Client.CrmConnection("Crm");
    XrmServiceContext xrm = new XrmServiceContext(Crm);

    Is it something that I am missing here?

    Thanks!

  • Sunday, 22 April 2012 12:20 AM
     
     
    Hi Abhi,
    Add the <microsoft.xrm.client> Node to your app.config file and change the cacheMode To Disabled In the serviceCache And objectCache  Nodes.



    Regards,
    Damian Sinay


    • Edited by dsinayMVP Sunday, 22 April 2012 12:21 AM
    •  
  • Sunday, 22 April 2012 6:59 PM
     
     

    Thanks for your reply dsinay!

    Will do the necessary changes and let you know. Thanks for your efforts.

    Thanks,
    Abhi

  • Monday, 23 April 2012 11:12 PM
     
      Has Code

    The updated app.config file looks like as shown below. But it throwing error while starting the windows service (Error 1053: The service did not respond to the start or control request in a timely fashion.)

    <?xml version="1.0"?>
    <configuration>
      <!--<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>-->
      <connectionStrings>
    
        <add name="Xrm" connectionString="Url=https://dev.link.co.uk; User ID=testuser; Password=password;"/>  </connectionStrings>
    
      <microsoft.xrm.client>
        <contexts default="Xrm">
          <add name="Xrm" type="Xrm.XrmServiceContext, Xrm" connectionStringName="Xrm" serviceName="Xrm"/>
        </contexts>
        <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=""
           slidingExpiration="00:00:00"
           duration="00:00:00"
           priority="Default"
           outputCacheProfileName="Xrm"/>
        </objectCache>
      </microsoft.xrm.client>
    
      <appSettings>
        <add key="Tracker" value="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=test"/>
      </appSettings>
      <system.net>
        <defaultProxy useDefaultCredentials="true">
          <proxy usesystemdefault="True" />
        </defaultProxy>
      </system.net>
    </configuration>
    

    Any idea on this?

    Thanks,
    Abhi

  • Wednesday, 25 April 2012 10:51 PM
     
      Has Code

    Hi dsinay,

    Added following <microsoft.xrm.client> to the app.config but due to this change, service is not starting (Error 1053: The service did not respond to the start or control request in a timely fashion.)

      <microsoft.xrm.client>
        <contexts default="Xrm">
          <add name="Xrm" type="Xrm.XrmServiceContext, Xrm" connectionStringName="Xrm" serviceName="Xrm"/>
        </contexts>
        <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=""
           slidingExpiration="00:00:00"
           duration="00:00:00" 
           priority="Default"
           outputCacheProfileName="Xrm"
       />
        </objectCache>
      </microsoft.xrm.client>
    

    Tried lots of other ways, but no success. Could you please let me know what's going wrong with the <microsoft.xrm.client> node.
    Early response is much appreciated.

    Thanks,
    Abhi