Best Practices for Better Performance from Your Custom Code

Use Multiple Threads

Add threading support to your application to break the work up across multiple CPU's. This assumes that you are running the code on a multi-processor system.

For more information see the NET Framework Developer's Guide article on Managed Threading at

Use NTLM Authentication

For more information see Designing Distributed Applications with Visual Studio .NET, IIS Authentication at

Use Connection Sharing

This is also called unsafe connection sharing. Connection sharing is safe when you are running an application as a single user. For example, if you write a program to do bulk import for a custom entity. If your application will have multiple users, you can create a separate application pool for the program to run in to increase the measure of safety when using connection sharing.


// Create the service.
CrmService _localService = new CrmService();
_localService.Credentials = _crmService.Credentials;
_localService.Url = _crmService.Url;
// Turn on unsafe connection sharing.
_localService.UnsafeAuthenticatedConnectionSharing = true;
// For a program with multiple users, create a new application pool
// rather than using the default.
_localService.ConnectionGroupName = "default";

For more information see the documentation for the .NET Framework Class Library HttpWebRequest.UnsafeAuthenticatedConnectionSharing property at

Use Common Methods

The CrmService common methods are faster than using the CrmService.Execute method with the corresponding message. For example use the Update method rather than the Execute method with the Update message.

Use Strong Types

The DynamicEntity class is useful for when your code needs to work on entities and attributes that are not known at the time the code is written. However, this flexibility comes at a price. If your entities are already defined at code time, you should use the strong types provided for you in the WSDL.

Disable Callouts

If possible, disable all registered callouts before running your application.

Limit Data Retrieved

When using the methods that retrieve data from the server, only retrieve the minimum amount of data needed by your application. This is done by specifying the column set, which is the set of entity attributes to retrieve.

When using the Retrieve method, use the columnSet parameter to specify the attributes you need.

When using the RetrieveMultiple method, specify the attributes to retrieve in the query using the QueryBase.ColumnSet field.

When using any message that uses a QueryExpression to specify the query criteria, use the QueryBase.ColumnSet field.

Limit Operations that Cascade to Related Entities

When using Update, don't set the ownerid attribute on an entity instance unless the owner has actually changed. Setting this attribute often requires changes to cascade to related entities, increasing the amount of time required for the update operation.

Amy Langlois

Comments (4)

  1. “We are facing a big trouble with a Batch process that we developed using SDK… The SDK “Create” and “Update”

  2. Philippe says:


    I tried the UnsafeAuthenticatedConnectionSharing and set it to true but everytime I do this, all the webservicealls fail. Do you have an idea?



  3. Bernard says:

    I am experiencing the same issue that you are talking about but the problem that i have is that it runs fine on our servers [test servers] but on our client server it terminates with a “Unable to connect to the remote server” . However when i run the process with only a few records to create it processes fine but once i do a bulk upload it fails after 30sec. I have tested the CRMService.Timeout which does not solve the problem and have checked <httpRuntime executionTimeout="300" maxRequestLength="8192"/> which seems fine. I create the webserver class and within the constructor i create the connection and authentication so will only do this once so don’t know if the UnsafeAuthenticatedConnectionSharing will apply to my instance. Would be grateful if someone could assist me…

    public CrmService service;


       private static object objLock;

       static string newOrgName;

       /// <summary>

       /// Please use UpdateCRMEntities(String par_OrgName) instead

       /// </summary>

       public UpdateCRMEntities()


           CrmAuthenticationToken token = new CrmAuthenticationToken();

           token.AuthenticationType = 0;

           token.OrganizationName = "Organisation name";

           service = new CrmService();

           //service.Timeout = 15000;

           service.Url = "http://localhostname:5555/mscrmservices/2007/crmservice.asmx&quot;;

           service.CrmAuthenticationTokenValue = token;

           service.Credentials = System.Net.CredentialCache.DefaultCredentials;



  4. UMTSA-Johan says:


    I know this is off the topic and not related to CRM.

    But thanks this helped me very much and resolved my Error, I had the same Error “Unable to Connect to Remote Server” and it was because I Executed a Project Server 2007 Get Web Method in a loop.

    And I think what happened was that it was TOO MUCH Web Request for the Server.

    I implemented “MyWebProjectService.UnsafeAuthenticatedConnectionSharing = true;” to my Web Service and it seems to be working fine now 

Skip to main content