This documentation is archived and is not being maintained.

Context Configurability

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

To configure various contexts with different connection strings or caching preferences within the same application, add context names to the contexts section of the <microsoft.xrm.client> section of your app.config/web.config. You can specify a type, service parameter, and connection string for each context. In the code, when you create the context, simply use the following:

var crm = new Xrm.XrmDataContext("NameOfConextFromConfig")

If no connectionStringName is specified, the connection string name matching the context name will be used. If no serviceName is specified, the service name matching the context name will be used, and if there isn't one, the default service name will be used.

<contexts default="Default">
         <add name="Default" type="Xrm.XrmDataContext, Xrm" connectionStringName="Xrm"
            serviceName="Default" />
         <add name="CacheTwoHours" type="Xrm.XrmDataContext, Xrm" connectionStringName="Xrm"
            serviceName="CacheTwoHours" />
         <add name="CacheMetadata" type="Xrm.XrmDataContext, Xrm" connectionStringName="Xrm"
            serviceName="CacheMetadata" />
         <add name="CacheDisabled" type="Xrm.XrmDataContext, Xrm" connectionStringName="Xrm"
            serviceName="CacheDisabled" />

Specify services  in the services section. You maycan specify a cache provider  and type for the service. For example, if you wish to cache the metadata, use type Microsoft.Xrm.Client.Services.CachedMetadataOrganizationService., iIf you want to disable caching, use Microsoft.Xrm.Client.Services.Organization Service.  If no type is specified, the system default will be used. If no cacheProviderName is not specified, the cache provider name matching the service name will be used, and if there isn't one the default cache provider name will be used.  You may also add cache provider customability;, for example, you maycan add a duration in order to specify the time limit of the caching.

<services default="Default">
         <add name="Default" cacheProviderName="Default" />
         <add name="CacheTwoHours" cacheProviderName="CacheTwoHours" />
         <add name="CacheMetadata"
            cacheProviderName="Default" />
         <add name="CacheDisabled" type="Microsoft.Xrm.Client.Services.OrganizationService" />
      <cache defaultProvider="Default">
            <add name="Default"
               type="Microsoft.Xrm.Client.Caching.InMemoryCacheProvider, Microsoft.Xrm.Client" />
            <add name="CacheTwoHours"
               type="Microsoft.Xrm.Client.Caching.InMemoryCacheProvider, Microsoft.Xrm.Client"
               duration="02:00:00" />

© 2010 Microsoft Corporation. All rights reserved.